diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/direct_bt/DBTManager.cpp | 8 | ||||
-rw-r--r-- | src/direct_bt/GATTHandler.cpp | 6 | ||||
-rw-r--r-- | src/direct_bt/HCIHandler.cpp | 6 |
3 files changed, 17 insertions, 3 deletions
diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp index afea062b..7572e4ba 100644 --- a/src/direct_bt/DBTManager.cpp +++ b/src/direct_bt/DBTManager.cpp @@ -37,6 +37,8 @@ // #define PERF3_PRINT_ON 1 #include <jau/debug.hpp> +#include <jau/basic_algos.hpp> + #include "BTIoctl.hpp" #include "DBTManager.hpp" @@ -87,6 +89,10 @@ void DBTManager::mgmtReaderThreadImpl() noexcept { DBG_PRINT("DBTManager::reader: Started"); cv_mgmtReaderInit.notify_all(); } + thread_local jau::call_on_release thread_cleanup([&]() { + DBG_PRINT("DBTManager::mgmtReaderThreadCleanup: mgmtReaderRunning %d -> 0", mgmtReaderRunning.load()); + mgmtReaderRunning = false; + }); while( !mgmtReaderShallStop ) { jau::snsize_t len; @@ -502,7 +508,7 @@ void DBTManager::close() noexcept { mgmtReaderThreadId = 0; const bool is_reader = tid_reader == tid_self; DBG_PRINT("DBTManager::close: mgmtReader[running %d, shallStop %d, isReader %d, tid %p)", - mgmtReaderRunning, mgmtReaderShallStop.load(), is_reader, (void*)tid_reader); + mgmtReaderRunning.load(), mgmtReaderShallStop.load(), is_reader, (void*)tid_reader); if( mgmtReaderRunning ) { mgmtReaderShallStop = true; if( !is_reader && 0 != tid_reader ) { diff --git a/src/direct_bt/GATTHandler.cpp b/src/direct_bt/GATTHandler.cpp index a1a27f96..b08b21ac 100644 --- a/src/direct_bt/GATTHandler.cpp +++ b/src/direct_bt/GATTHandler.cpp @@ -196,6 +196,10 @@ void GATTHandler::l2capReaderThreadImpl() { DBG_PRINT("GATTHandler::reader Started"); cv_l2capReaderInit.notify_all(); } + thread_local jau::call_on_release thread_cleanup([&]() { + DBG_PRINT("GATTHandler::l2capReaderThreadCleanup: l2capReaderRunning %d -> 0", l2capReaderRunning.load()); + l2capReaderRunning = false; + }); while( !l2capReaderShallStop ) { jau::snsize_t len; @@ -370,7 +374,7 @@ bool GATTHandler::disconnect(const bool disconnectDevice, const bool ioErrorCaus l2capReaderThreadId = 0; const bool is_l2capReader = tid_l2capReader == tid_self; DBG_PRINT("GATTHandler.disconnect: l2capReader[running %d, shallStop %d, isReader %d, tid %p)", - l2capReaderRunning, l2capReaderShallStop.load(), is_l2capReader, (void*)tid_l2capReader); + l2capReaderRunning.load(), l2capReaderShallStop.load(), is_l2capReader, (void*)tid_l2capReader); if( l2capReaderRunning ) { l2capReaderShallStop = true; if( !is_l2capReader && 0 != tid_l2capReader ) { diff --git a/src/direct_bt/HCIHandler.cpp b/src/direct_bt/HCIHandler.cpp index 92cdfd93..f0c178b4 100644 --- a/src/direct_bt/HCIHandler.cpp +++ b/src/direct_bt/HCIHandler.cpp @@ -274,6 +274,10 @@ void HCIHandler::hciReaderThreadImpl() noexcept { DBG_PRINT("HCIHandler::reader: Started - %s", toString().c_str()); cv_hciReaderInit.notify_all(); } + thread_local jau::call_on_release thread_cleanup([&]() { + DBG_PRINT("HCIHandler::hciReaderThreadCleanup: hciReaderRunning %d -> 0", hciReaderRunning.load()); + hciReaderRunning = false; + }); while( !hciReaderShallStop ) { jau::snsize_t len; @@ -571,7 +575,7 @@ void HCIHandler::close() noexcept { hciReaderThreadId = 0; const bool is_reader = tid_reader == tid_self; DBG_PRINT("HCIHandler::close: hciReader[running %d, shallStop %d, isReader %d, tid %p) - %s", - hciReaderRunning, hciReaderShallStop.load(), is_reader, (void*)tid_reader, toString().c_str()); + hciReaderRunning.load(), hciReaderShallStop.load(), is_reader, (void*)tid_reader, toString().c_str()); if( hciReaderRunning ) { hciReaderShallStop = true; if( !is_reader && 0 != tid_reader ) { |