Fix build issue with mutex

This commit is contained in:
David 2024-08-31 19:40:54 +10:00
parent 6c0911038a
commit eb1f80f520
2 changed files with 6 additions and 11 deletions

View File

@ -65,21 +65,18 @@ bool BMP3XXSensor::getMetrics(meshtastic_Telemetry *measurement)
// Get a singleton wrapper for an Adafruit_bmp3xx // Get a singleton wrapper for an Adafruit_bmp3xx
BMP3XXSingleton *BMP3XXSingleton::GetInstance() BMP3XXSingleton *BMP3XXSingleton::GetInstance()
{ {
std::lock_guard<std::mutex> lock(mutex_); if (pinstance == nullptr)
if (pinstance_ == nullptr)
{ {
pinstance_ = new BMP3XXSingleton(); pinstance = new BMP3XXSingleton();
} }
return pinstance_; return pinstance;
} }
BMP3XXSingleton::BMP3XXSingleton(){} BMP3XXSingleton::BMP3XXSingleton(){}
BMP3XXSingleton::~BMP3XXSingleton(){} BMP3XXSingleton::~BMP3XXSingleton(){}
BMP3XXSingleton* BMP3XXSingleton::pinstance_{nullptr}; BMP3XXSingleton* BMP3XXSingleton::pinstance{nullptr};
std::mutex BMP3XXSingleton::mutex_;
bool BMP3XXSingleton::performReading() bool BMP3XXSingleton::performReading()
{ {

View File

@ -7,7 +7,6 @@
#define SEAL_LEVEL_HPA 1013.2f #define SEAL_LEVEL_HPA 1013.2f
#include <mutex>
#include <typeinfo> #include <typeinfo>
#include <Adafruit_BMP3XX.h> #include <Adafruit_BMP3XX.h>
#include "TelemetrySensor.h" #include "TelemetrySensor.h"
@ -16,15 +15,14 @@
class BMP3XXSingleton : public Adafruit_BMP3XX class BMP3XXSingleton : public Adafruit_BMP3XX
{ {
private: private:
static BMP3XXSingleton * pinstance_; static BMP3XXSingleton * pinstance;
static std::mutex mutex_;
protected: protected:
BMP3XXSingleton(); BMP3XXSingleton();
~BMP3XXSingleton(); ~BMP3XXSingleton();
public: public:
// Create a singleton instance (with lock for thread safety) // Create a singleton instance (not thread safe)
static BMP3XXSingleton *GetInstance(); static BMP3XXSingleton *GetInstance();
// Singletons should not be cloneable. // Singletons should not be cloneable.