summaryrefslogtreecommitdiffstats
path: root/src/direct_bt/SMPHandler.cpp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-11-16 08:31:51 +0100
committerSven Gothel <[email protected]>2021-11-16 08:31:51 +0100
commitc8c633b821cb12a5ffe38d07a9d7e622b020b415 (patch)
treef14a126a4eb1e887fec3cb344b750a9408494fe9 /src/direct_bt/SMPHandler.cpp
parent8f2edee64c8b4cec6c287ef61d8f398d8f59dd2b (diff)
Unlock mutex before notify_all to avoid pessimistic re-block of notified wait() thread
Holding the same lock @ notify_all as the waiting thread, would lead to waking up the waiting thread, which only would be blocked again as it attempts to re-acquire the lock.
Diffstat (limited to 'src/direct_bt/SMPHandler.cpp')
-rw-r--r--src/direct_bt/SMPHandler.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/direct_bt/SMPHandler.cpp b/src/direct_bt/SMPHandler.cpp
index 12cfa6db..a5a4deca 100644
--- a/src/direct_bt/SMPHandler.cpp
+++ b/src/direct_bt/SMPHandler.cpp
@@ -105,8 +105,9 @@ void SMPHandler::l2capReaderThreadImpl() {
l2capReaderShallStop = false;
l2capReaderRunning = true;
DBG_PRINT("SMPHandler::reader Started");
- cv_l2capReaderInit.notify_all();
}
+ cv_l2capReaderInit.notify_all(); // have mutex unlocked before notify_all to avoid pessimistic re-block of notified wait() thread.
+
thread_local jau::call_on_release thread_cleanup([&]() {
DBG_PRINT("SMPHandler::l2capReaderThreadCleanup: l2capReaderRunning %d -> 0", l2capReaderRunning.load());
l2capReaderRunning = false;
@@ -156,8 +157,9 @@ void SMPHandler::l2capReaderThreadImpl() {
WORDY_PRINT("SMPHandler::reader: Ended. Ring has %u entries flushed", smpPDURing.size());
smpPDURing.clear();
l2capReaderRunning = false;
- cv_l2capReaderInit.notify_all();
}
+ cv_l2capReaderInit.notify_all(); // have mutex unlocked before notify_all to avoid pessimistic re-block of notified wait() thread.
+
disconnect(true /* disconnectDevice */, has_ioerror);
}