aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-05-28 19:10:28 +0200
committerSven Gothel <[email protected]>2020-05-28 19:10:28 +0200
commit93c70956beddc007ba615b850401eb16cc9683dd (patch)
tree9fee37629c9130d42037870db767b9eae3a19b4f /api
parentfafc8db2ed2f2975148665e7224412b72ac03df2 (diff)
Use atomic as a memory barrier (data race), volatile is not suitable for multithreading.
Diffstat (limited to 'api')
-rw-r--r--api/direct_bt/DBTAdapter.hpp4
-rw-r--r--api/direct_bt/DBTManager.hpp4
-rw-r--r--api/direct_bt/LFRingbuffer.hpp10
3 files changed, 9 insertions, 9 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];