mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-04-28 21:57:57 +03:00
Notify the request thread of shutdown only if it's waiting
This avoids a deadlock that would occur if notify_all() is called before the thread is waiting
This commit is contained in:
parent
456b660b2a
commit
06a12246f5
2 changed files with 12 additions and 11 deletions
|
@ -210,7 +210,13 @@ void UpdateCheckerThread::Shutdown()
|
|||
|
||||
if (osThread) {
|
||||
// Notify and shutdown the thread
|
||||
clientWake.notify_all();
|
||||
{
|
||||
// Wait until the request thread is ready
|
||||
std::lock_guard<std::mutex> l(clientWakeMutex);
|
||||
clientWake.notify_all();
|
||||
}
|
||||
|
||||
// Wait for the thread to exit
|
||||
osThread->join();
|
||||
|
||||
delete osThread;
|
||||
|
@ -358,19 +364,15 @@ void UpdateCheckerThread::RequestThread()
|
|||
InitClient();
|
||||
|
||||
while (handle && shouldBeActive) {
|
||||
std::unique_lock<std::mutex> l(clientWakeMutex);
|
||||
DoRequest();
|
||||
RequestThreadSleep();
|
||||
|
||||
const std::chrono::seconds interval = std::chrono::seconds(Q_max(1, com_updatecheck_interval->integer) * 60);
|
||||
|
||||
clientWake.wait_for(l, interval);
|
||||
}
|
||||
|
||||
ShutdownClient();
|
||||
|
||||
requestThreadIsActive = qfalse;
|
||||
}
|
||||
|
||||
void UpdateCheckerThread::RequestThreadSleep()
|
||||
{
|
||||
const std::chrono::seconds interval = std::chrono::seconds(Q_max(1, com_updatecheck_interval->integer) * 60);
|
||||
|
||||
std::unique_lock<std::mutex> l(clientWakeMutex);
|
||||
clientWake.wait_for(l, interval);
|
||||
}
|
||||
|
|
|
@ -61,7 +61,6 @@ private:
|
|||
|
||||
bool ParseVersionNumber(const char *value, int& major, int& minor, int& patch) const;
|
||||
void RequestThread();
|
||||
void RequestThreadSleep();
|
||||
void DoRequest();
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue