From 1f0778b14e2e0c35d102219d6dee29dbeb99d70c Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 15 Sep 2006 21:39:20 +0000 Subject: [PATCH] Fixed threader not checking the state on looping --- dlls/mysqlx/thread/ThreadWorker.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/dlls/mysqlx/thread/ThreadWorker.cpp b/dlls/mysqlx/thread/ThreadWorker.cpp index daff21ed..4c061067 100644 --- a/dlls/mysqlx/thread/ThreadWorker.cpp +++ b/dlls/mysqlx/thread/ThreadWorker.cpp @@ -54,6 +54,9 @@ void ThreadWorker::RunThread(IThreadHandle *pHandle) /** * Check number of items in the queue */ + m_StateLock->Lock(); + this_state = m_state; + m_StateLock->Unlock(); if (this_state != Worker_Stopped) { m_QueueLock->Lock(); @@ -65,6 +68,11 @@ void ThreadWorker::RunThread(IThreadHandle *pHandle) */ m_Waiting = true; m_QueueLock->Unlock(); + /* first check if we should end again */ + if (this_state == Worker_Stopped) + { + break; + } m_AddSignal->Wait(); m_Waiting = false; } else { @@ -80,7 +88,9 @@ void ThreadWorker::RunThread(IThreadHandle *pHandle) { //wait until the lock is cleared. if (this_state == Worker_Paused) + { m_PauseSignal->Wait(); + } if (this_state == Worker_Stopped) { //if we're supposed to flush cleanrly, @@ -187,9 +197,12 @@ bool ThreadWorker::Stop(bool flush_cancel) { Unpause(); } else { - m_AddSignal->Signal(); - Pause(); - Unpause(); + m_QueueLock->Lock(); + if (m_Waiting) + { + m_AddSignal->Signal(); + } + m_QueueLock->Unlock(); } me->WaitForThread();