diff options
author | Paul Nettle <nettle.paul@gmail.com> | 2017-10-12 11:38:48 -0500 |
---|---|---|
committer | Paul Nettle <nettle.paul@gmail.com> | 2017-10-12 11:38:48 -0500 |
commit | d6e33388be363f3742a20d306dfe8c139dd45196 (patch) | |
tree | e01796254a2aa9c57c5d1a72f85807b5d33da0e2 /src/HciAdapter.h | |
parent | Improved threading support, cleaner initialization process and added the abil... (diff) | |
download | gobbledegook-d6e33388be363f3742a20d306dfe8c139dd45196.tar.gz gobbledegook-d6e33388be363f3742a20d306dfe8c139dd45196.tar.bz2 gobbledegook-d6e33388be363f3742a20d306dfe8c139dd45196.zip |
Fixed a race condition while waiting for command responses from the HCI adapter
Diffstat (limited to 'src/HciAdapter.h')
-rw-r--r-- | src/HciAdapter.h | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/HciAdapter.h b/src/HciAdapter.h index ad4f62a..bcd93e3 100644 --- a/src/HciAdapter.h +++ b/src/HciAdapter.h @@ -485,12 +485,17 @@ public: private: // Private constructor for our Singleton - HciAdapter() : activeConnections(0) {} + HciAdapter() : commandResponseLock(commandResponseMutex), activeConnections(0) {} // Uses a std::condition_variable to wait for a response event for the given `commandCode` or `timeoutMS` milliseconds. // // Returns true if the response event was received for `commandCode` or false if the timeout expired. - bool waitFor(uint16_t commandCode, int timeoutMS); + // + // Command responses are set via `setCommandResponse()` + bool waitForCommandResponse(uint16_t commandCode, int timeoutMS); + + // Sets the command response and notifies the waiting std::condition_variable (see `waitForCommandResponse`) + void setCommandResponse(uint16_t commandCode); // Our HCI Socket, which allows us to talk directly to the kernel HciSocket hciSocket; @@ -504,7 +509,9 @@ private: VersionInformation versionInformation; LocalName localName; - std::condition_variable conditionalWait; + std::condition_variable cvCommandResponse; + std::mutex commandResponseMutex; + std::unique_lock<std::mutex> commandResponseLock; int conditionalValue; // Our active connection count |