From d214fe1b125d9e1569b65ffe609a3f29dd5c7701 Mon Sep 17 00:00:00 2001 From: Wiebe Cazemier Date: Sun, 1 Dec 2024 14:41:47 +0100 Subject: [PATCH] Break up waiting on quit into two stages Now that our quit event is queued, we can properly wait for it. This way, we can separate waiting for quit and waiting for (possibly hanging) plugins. --- mainapp.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mainapp.cpp b/mainapp.cpp index c0241d8..8a24a6b 100644 --- a/mainapp.cpp +++ b/mainapp.cpp @@ -962,12 +962,23 @@ void MainApp::start() oneInstanceLock.unlock(); - logger->logf(LOG_DEBUG, "Waiting for threads to finish."); + { + logger->logf(LOG_DEBUG, "Waiting for our own quit event to have been queued."); + int count = 0; + while(std::any_of(threads.begin(), threads.end(), [](std::shared_ptr t){ return t->running; })) + { + if (count++ >= 30000) + break; + usleep(1000); + } + } + + logger->logf(LOG_DEBUG, "Waiting for threads clean-up functions to finish."); int count = 0; bool waitTimeExpired = false; while(std::any_of(threads.begin(), threads.end(), [](std::shared_ptr t){ return !t->finished; })) { - if (count++ >= 10000) + if (count++ >= 30000) { waitTimeExpired = true; break;