diff options
-rw-r--r-- | api/direct_bt/DBTAdapter.hpp | 4 | ||||
-rw-r--r-- | api/direct_bt/DBTManager.hpp | 4 | ||||
-rw-r--r-- | api/direct_bt/LFRingbuffer.hpp | 10 | ||||
-rw-r--r-- | src/direct_bt/DBTAdapter.cpp | 4 |
4 files changed, 12 insertions, 10 deletions
diff --git a/api/direct_bt/DBTAdapter.hpp b/api/direct_bt/DBTAdapter.hpp index 14badc12..0a9f6c87 100644 --- a/api/direct_bt/DBTAdapter.hpp +++ b/api/direct_bt/DBTAdapter.hpp @@ -160,7 +160,7 @@ namespace direct_bt { std::recursive_mutex mtx_discoveredDevices; std::recursive_mutex mtx_sharedDevices; std::recursive_mutex mtx_statusListenerList; - volatile bool keepDiscoveringAlive = false; + std::atomic<bool> keepDiscoveringAlive; // = false; bool validateDevInfo(); @@ -196,7 +196,7 @@ namespace direct_bt { void startDiscoveryBackground(); - void sendDeviceUpdated(std::shared_ptr<DBTDevice> device, uint64_t timestamp, EIRDataType updateMask); + void sendDeviceUpdated(std::string cause, std::shared_ptr<DBTDevice> device, uint64_t timestamp, EIRDataType updateMask); public: diff --git a/api/direct_bt/DBTManager.hpp b/api/direct_bt/DBTManager.hpp index 76642c78..51c6d612 100644 --- a/api/direct_bt/DBTManager.hpp +++ b/api/direct_bt/DBTManager.hpp @@ -118,8 +118,8 @@ namespace direct_bt { LFRingbuffer<std::shared_ptr<MgmtEvent>, nullptr> mgmtEventRing; std::thread mgmtReaderThread; - volatile bool mgmtReaderRunning; - volatile bool mgmtReaderShallStop; + std::atomic<bool> mgmtReaderRunning; + std::atomic<bool> mgmtReaderShallStop; /** One MgmtAdapterEventCallbackList per event type, allowing multiple callbacks to be invoked for each event */ std::array<MgmtAdapterEventCallbackList, static_cast<uint16_t>(MgmtEvent::Opcode::MGMT_EVENT_TYPE_COUNT)> mgmtAdapterEventCallbackLists; diff --git a/api/direct_bt/LFRingbuffer.hpp b/api/direct_bt/LFRingbuffer.hpp index 1010b540..14447664 100644 --- a/api/direct_bt/LFRingbuffer.hpp +++ b/api/direct_bt/LFRingbuffer.hpp @@ -85,11 +85,11 @@ template <typename T, std::nullptr_t nullelem> class LFRingbuffer : public Ringb std::condition_variable cvRead; std::condition_variable cvWrite; - /* final */ int volatile capacityPlusOne; // not final due to grow - /* final */ T * volatile array; // not final due to grow - int volatile readPos; - int volatile writePos; - std::atomic_int size; + /* final */ int capacityPlusOne; // not final due to grow + /* final */ T * array; // not final due to grow + std::atomic<int> readPos; + std::atomic<int> writePos; + std::atomic<int> size; T * newArray(const int count) { return new T[count]; diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp index 948d02eb..ca8db464 100644 --- a/src/direct_bt/DBTAdapter.cpp +++ b/src/direct_bt/DBTAdapter.cpp @@ -104,6 +104,8 @@ std::shared_ptr<DBTDevice> DBTAdapter::findConnectedDevice (EUI48 const & mac) c // ************************************************* bool DBTAdapter::validateDevInfo() { + keepDiscoveringAlive = false; + if( !mgmt.isOpen() || 0 > dev_id ) { return false; } @@ -435,7 +437,7 @@ std::string DBTAdapter::toString() const { bool DBTAdapter::mgmtEvDeviceDiscoveringCB(std::shared_ptr<MgmtEvent> e) { DBG_PRINT("DBTAdapter::EventCB:DeviceDiscovering(dev_id %d, keepDiscoveringAlive %d): %s", - dev_id, keepDiscoveringAlive, e->toString().c_str()); + dev_id, keepDiscoveringAlive.load(), e->toString().c_str()); const MgmtEvtDiscovering &event = *static_cast<const MgmtEvtDiscovering *>(e.get()); const bool enabled = event.getEnabled(); for_each_idx_mtx(mtx_statusListenerList, statusListenerList, [&](std::shared_ptr<AdapterStatusListener> &l) { |