Added TaskScheduler::GetWorkerCount()
Former-commit-id: db4bf747441a13f2d824410aa5be264b300e95d4
This commit is contained in:
parent
e699969b64
commit
6f495c654a
|
|
@ -16,6 +16,7 @@ class NAZARA_API NzTaskScheduler
|
||||||
template<typename F> static void AddTask(F function);
|
template<typename F> static void AddTask(F function);
|
||||||
template<typename F, typename... Args> static void AddTask(F function, Args... args);
|
template<typename F, typename... Args> static void AddTask(F function, Args... args);
|
||||||
template<typename C> static void AddTask(void (C::*function)(), C* object);
|
template<typename C> static void AddTask(void (C::*function)(), C* object);
|
||||||
|
static unsigned int GetWorkerCount();
|
||||||
static bool Initialize();
|
static bool Initialize();
|
||||||
static void Uninitialize();
|
static void Uninitialize();
|
||||||
static void WaitForTasks();
|
static void WaitForTasks();
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ namespace
|
||||||
s_impl->waiterConditionVariable.SignalAll();
|
s_impl->waiterConditionVariable.SignalAll();
|
||||||
s_impl->waiterConditionVariableMutex.Unlock();
|
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->workerConditionVariableMutex.Lock();
|
||||||
s_impl->workerConditionVariable.Wait(&s_impl->workerConditionVariableMutex);
|
s_impl->workerConditionVariable.Wait(&s_impl->workerConditionVariableMutex);
|
||||||
s_impl->workerConditionVariableMutex.Unlock();
|
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()
|
bool NzTaskScheduler::Initialize()
|
||||||
{
|
{
|
||||||
if (s_impl)
|
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()
|
void NzTaskScheduler::WaitForTasks()
|
||||||
{
|
{
|
||||||
#ifdef NAZARA_CORE_SAFE
|
#ifdef NAZARA_CORE_SAFE
|
||||||
|
|
@ -146,3 +139,23 @@ void NzTaskScheduler::WaitForTasks()
|
||||||
s_impl->waiterConditionVariable.Wait(&s_impl->waiterConditionVariableMutex);
|
s_impl->waiterConditionVariable.Wait(&s_impl->waiterConditionVariableMutex);
|
||||||
s_impl->waiterConditionVariableMutex.Unlock();
|
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();
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue