Added TaskScheduler::GetWorkerCount()

Former-commit-id: db4bf747441a13f2d824410aa5be264b300e95d4
This commit is contained in:
Lynix
2012-12-06 01:01:26 +01:00
parent e699969b64
commit 6f495c654a
2 changed files with 35 additions and 21 deletions

View File

@@ -54,7 +54,7 @@ namespace
s_impl->waiterConditionVariable.SignalAll();
s_impl->waiterConditionVariableMutex.Unlock();
// Dans le cas contraire, nous attendons qu'une nouvelle tâche arrive
// Nous attendons qu'une nouvelle tâche arrive
s_impl->workerConditionVariableMutex.Lock();
s_impl->workerConditionVariable.Wait(&s_impl->workerConditionVariableMutex);
s_impl->workerConditionVariableMutex.Unlock();
@@ -64,6 +64,19 @@ namespace
}
}
unsigned int NzTaskScheduler::GetWorkerCount()
{
#ifdef NAZARA_CORE_SAFE
if (!s_impl)
{
NazaraError("Task scheduler is not initialized");
return 0;
}
#endif
return s_impl->workers.size();
}
bool NzTaskScheduler::Initialize()
{
if (s_impl)
@@ -101,26 +114,6 @@ void NzTaskScheduler::Uninitialize()
}
}
void NzTaskScheduler::AddTaskFunctor(NzFunctor* taskFunctor)
{
#ifdef NAZARA_CORE_SAFE
if (!s_impl)
{
NazaraError("Task scheduler is not initialized");
return;
}
#endif
{
NzLockGuard lock(s_impl->taskMutex);
s_impl->tasks.push(taskFunctor);
}
s_impl->workerConditionVariableMutex.Lock();
s_impl->workerConditionVariable.Signal();
s_impl->workerConditionVariableMutex.Unlock();
}
void NzTaskScheduler::WaitForTasks()
{
#ifdef NAZARA_CORE_SAFE
@@ -146,3 +139,23 @@ void NzTaskScheduler::WaitForTasks()
s_impl->waiterConditionVariable.Wait(&s_impl->waiterConditionVariableMutex);
s_impl->waiterConditionVariableMutex.Unlock();
}
void NzTaskScheduler::AddTaskFunctor(NzFunctor* taskFunctor)
{
#ifdef NAZARA_CORE_SAFE
if (!s_impl)
{
NazaraError("Task scheduler is not initialized");
return;
}
#endif
{
NzLockGuard lock(s_impl->taskMutex);
s_impl->tasks.push(taskFunctor);
}
s_impl->workerConditionVariableMutex.Lock();
s_impl->workerConditionVariable.Signal();
s_impl->workerConditionVariableMutex.Unlock();
}