Seems more correct
Former-commit-id: fa83f37d65c97bd5bfb7840865fab0e838804c30
This commit is contained in:
parent
2cb669a558
commit
2cb6fca127
|
|
@ -76,17 +76,14 @@ void NzTaskSchedulerImpl::Uninitialize()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// On réveille les threads pour qu'ils sortent de la boucle et terminent.
|
||||||
|
pthread_mutex_lock(&s_mutexQueue);
|
||||||
// On commence par vider la queue et demander qu'ils s'arrêtent.
|
// On commence par vider la queue et demander qu'ils s'arrêtent.
|
||||||
|
std::queue<NzFunctor*> emptyQueue;
|
||||||
|
std::swap(s_tasks, emptyQueue);
|
||||||
s_shouldFinish = true;
|
s_shouldFinish = true;
|
||||||
|
pthread_cond_broadcast(&s_cvNotEmpty);
|
||||||
ClearQueue();
|
pthread_mutex_unlock(&s_mutexQueue);
|
||||||
|
|
||||||
{
|
|
||||||
// On réveille les threads pour qu'ils sortent de la boucle et terminent.
|
|
||||||
pthread_mutex_lock(&s_mutexQueue);
|
|
||||||
pthread_cond_broadcast(&s_cvNotEmpty);
|
|
||||||
pthread_mutex_unlock(&s_mutexQueue);
|
|
||||||
}
|
|
||||||
|
|
||||||
// On attend que chaque thread se termine
|
// On attend que chaque thread se termine
|
||||||
for (unsigned int i = 0; i < s_workerCount; ++i)
|
for (unsigned int i = 0; i < s_workerCount; ++i)
|
||||||
|
|
@ -114,14 +111,6 @@ void NzTaskSchedulerImpl::WaitForTasks()
|
||||||
Wait();
|
Wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzTaskSchedulerImpl::ClearQueue()
|
|
||||||
{
|
|
||||||
pthread_mutex_lock(&s_mutexQueue);
|
|
||||||
std::queue<NzFunctor*> emptyQueue;
|
|
||||||
std::swap(s_tasks, emptyQueue);
|
|
||||||
pthread_mutex_unlock(&s_mutexQueue);
|
|
||||||
}
|
|
||||||
|
|
||||||
NzFunctor* NzTaskSchedulerImpl::PopQueue()
|
NzFunctor* NzTaskSchedulerImpl::PopQueue()
|
||||||
{
|
{
|
||||||
NzFunctor* task = nullptr;
|
NzFunctor* task = nullptr;
|
||||||
|
|
@ -144,14 +133,12 @@ void NzTaskSchedulerImpl::Wait()
|
||||||
if (s_isDone)
|
if (s_isDone)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!s_isDone)
|
pthread_mutex_lock(&s_mutexQueue);
|
||||||
{
|
s_isWaiting = true;
|
||||||
s_isWaiting = true;
|
pthread_cond_broadcast(&s_cvNotEmpty);
|
||||||
pthread_mutex_lock(&s_mutexQueue);
|
pthread_cond_wait(&s_cvEmpty, &s_mutexQueue);
|
||||||
pthread_cond_broadcast(&s_cvNotEmpty);
|
pthread_mutex_unlock(&s_mutexQueue);
|
||||||
pthread_cond_wait(&s_cvEmpty, &s_mutexQueue);
|
|
||||||
pthread_mutex_unlock(&s_mutexQueue);
|
|
||||||
}
|
|
||||||
s_isDone = true;
|
s_isDone = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ class NzTaskSchedulerImpl
|
||||||
static void WaitForTasks();
|
static void WaitForTasks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void ClearQueue();
|
|
||||||
static NzFunctor* PopQueue();
|
static NzFunctor* PopQueue();
|
||||||
static void Wait();
|
static void Wait();
|
||||||
static void* WorkerProc(void* userdata);
|
static void* WorkerProc(void* userdata);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue