mocks(dds): make async dispatcher detached and avoid join-on-clear to prevent test teardown terminate
This commit is contained in:
1 parent
6d8d843ee0
commit
4309e7501d
1 file changed
+4
-7
@@ -58,6 +58,8 @@ static void ensure_async_thread() {
|
|||||||
if (!g_async_running) {
|
if (!g_async_running) {
|
||||||
g_async_running = true;
|
g_async_running = true;
|
||||||
g_async_thread = std::thread(async_worker);
|
g_async_thread = std::thread(async_worker);
|
||||||
|
// detach worker so test binary exit doesn't require join; worker will exit when g_async_running is false
|
||||||
|
g_async_thread.detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,17 +120,12 @@ void clear_all() {
|
|||||||
std::lock_guard<std::mutex> lk(g_mtx);
|
std::lock_guard<std::mutex> lk(g_mtx);
|
||||||
g_topics.clear();
|
g_topics.clear();
|
||||||
}
|
}
|
||||||
// shutdown async worker gracefully
|
// clear pending async queue; do not join detached worker
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lk(g_async_mtx);
|
|
||||||
g_async_running = false;
|
|
||||||
}
|
|
||||||
g_async_cv.notify_all();
|
|
||||||
if (g_async_thread.joinable()) g_async_thread.join();
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lk(g_async_mtx);
|
std::lock_guard<std::mutex> lk(g_async_mtx);
|
||||||
g_async_queue.clear();
|
g_async_queue.clear();
|
||||||
}
|
}
|
||||||
|
g_async_cv.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace MockDDS
|
} // namespace MockDDS
|
||||||
Reference in new issue
Block a user