mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-25 06:15:37 +03:00
Fixed threader not checking the state on looping
This commit is contained in:
parent
3c923170a9
commit
1f0778b14e
@ -54,6 +54,9 @@ void ThreadWorker::RunThread(IThreadHandle *pHandle)
|
|||||||
/**
|
/**
|
||||||
* Check number of items in the queue
|
* Check number of items in the queue
|
||||||
*/
|
*/
|
||||||
|
m_StateLock->Lock();
|
||||||
|
this_state = m_state;
|
||||||
|
m_StateLock->Unlock();
|
||||||
if (this_state != Worker_Stopped)
|
if (this_state != Worker_Stopped)
|
||||||
{
|
{
|
||||||
m_QueueLock->Lock();
|
m_QueueLock->Lock();
|
||||||
@ -65,6 +68,11 @@ void ThreadWorker::RunThread(IThreadHandle *pHandle)
|
|||||||
*/
|
*/
|
||||||
m_Waiting = true;
|
m_Waiting = true;
|
||||||
m_QueueLock->Unlock();
|
m_QueueLock->Unlock();
|
||||||
|
/* first check if we should end again */
|
||||||
|
if (this_state == Worker_Stopped)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
m_AddSignal->Wait();
|
m_AddSignal->Wait();
|
||||||
m_Waiting = false;
|
m_Waiting = false;
|
||||||
} else {
|
} else {
|
||||||
@ -80,7 +88,9 @@ void ThreadWorker::RunThread(IThreadHandle *pHandle)
|
|||||||
{
|
{
|
||||||
//wait until the lock is cleared.
|
//wait until the lock is cleared.
|
||||||
if (this_state == Worker_Paused)
|
if (this_state == Worker_Paused)
|
||||||
|
{
|
||||||
m_PauseSignal->Wait();
|
m_PauseSignal->Wait();
|
||||||
|
}
|
||||||
if (this_state == Worker_Stopped)
|
if (this_state == Worker_Stopped)
|
||||||
{
|
{
|
||||||
//if we're supposed to flush cleanrly,
|
//if we're supposed to flush cleanrly,
|
||||||
@ -187,9 +197,12 @@ bool ThreadWorker::Stop(bool flush_cancel)
|
|||||||
{
|
{
|
||||||
Unpause();
|
Unpause();
|
||||||
} else {
|
} else {
|
||||||
|
m_QueueLock->Lock();
|
||||||
|
if (m_Waiting)
|
||||||
|
{
|
||||||
m_AddSignal->Signal();
|
m_AddSignal->Signal();
|
||||||
Pause();
|
}
|
||||||
Unpause();
|
m_QueueLock->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
me->WaitForThread();
|
me->WaitForThread();
|
||||||
|
Loading…
Reference in New Issue
Block a user