diff options
author | Sven Gothel <[email protected]> | 2021-11-17 07:07:22 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-11-17 07:07:22 +0100 |
commit | 29d385fa934f468b1f56b56eb3628a2995c19914 (patch) | |
tree | d7ff5250912249a35d915002e937035f21a3e615 /src/direct_bt/BTGattHandler.cpp | |
parent | e0e38ab5bddc62b059c2c56569c4b693e19b8ef7 (diff) |
Inrcrease Reader-Callback Shutdown Robustness: Limited time (8s) and have thread_local jau::call_on_release notify_all()
In certain (system) shutdown cases, it might occure that we encounter an uncontrolled/undefined behavior.
Limit time to wait for the reader thread to close to 8s (safe).
Also have the thread_local jau::call_on_release notify_all(),
which was missing.
Diffstat (limited to 'src/direct_bt/BTGattHandler.cpp')
-rw-r--r-- | src/direct_bt/BTGattHandler.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/direct_bt/BTGattHandler.cpp b/src/direct_bt/BTGattHandler.cpp index 38505543..1c6840e3 100644 --- a/src/direct_bt/BTGattHandler.cpp +++ b/src/direct_bt/BTGattHandler.cpp @@ -57,6 +57,7 @@ extern "C" { #include "BTManager.hpp" #include "BTAdapter.hpp" #include "BTManager.hpp" +#include "DBTConst.hpp" using namespace direct_bt; @@ -926,6 +927,7 @@ void BTGattHandler::l2capReaderThreadImpl() { thread_local jau::call_on_release thread_cleanup([&]() { DBG_PRINT("GATTHandler::l2capReaderThreadCleanup: l2capReaderRunning %d -> 0", l2capReaderRunning.load()); l2capReaderRunning = false; + cv_l2capReaderInit.notify_all(); }); while( !l2capReaderShallStop ) { @@ -1183,7 +1185,11 @@ bool BTGattHandler::disconnect(const bool disconnectDevice, const bool ioErrorCa } // Ensure the reader thread has ended, no runaway-thread using *this instance after destruction while( true == l2capReaderRunning ) { - cv_l2capReaderInit.wait(lockReader); + std::chrono::steady_clock::time_point t0 = std::chrono::steady_clock::now(); + std::cv_status s = cv_l2capReaderInit.wait_until(lockReader, t0 + std::chrono::milliseconds(THREAD_SHUTDOWN_TIMEOUT_MS)); + if( std::cv_status::timeout == s && true == l2capReaderRunning ) { + ERR_PRINT("GattHandler::disconnect::l2capReader: Timeout: %s", toString().c_str()); + } } } } |