Documentation for Thread
Former-commit-id: b33bbdf473792ddcde8ffbe310722d83a1a12bcf
This commit is contained in:
@@ -24,16 +24,39 @@ namespace Nz
|
||||
unsigned int s_workerCount = 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \class Nz::TaskScheduler<T>
|
||||
* \brief Core class that represents a pool of threads
|
||||
*
|
||||
* \remark Initialized should be called first
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Gets the number of threads
|
||||
* \return Number of threads, if none, the number of simulatenous threads on the processor is returned
|
||||
*/
|
||||
|
||||
unsigned int TaskScheduler::GetWorkerCount()
|
||||
{
|
||||
return (s_workerCount > 0) ? s_workerCount : HardwareInfo::GetProcessorCount();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Initializes the TaskScheduler class
|
||||
* \return true if everything is ok
|
||||
*/
|
||||
|
||||
bool TaskScheduler::Initialize()
|
||||
{
|
||||
return TaskSchedulerImpl::Initialize(GetWorkerCount());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Runs the pending works
|
||||
*
|
||||
* \remark Produce a NazaraError if the class is not initialized
|
||||
*/
|
||||
|
||||
void TaskScheduler::Run()
|
||||
{
|
||||
if (!Initialize())
|
||||
@@ -49,6 +72,14 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the number of workers
|
||||
*
|
||||
* \param workerCount Number of simulatnous threads handling the tasks
|
||||
*
|
||||
* \remark Produce a NazaraError if the class is not initialized and NAZARA_CORE_SAFE is defined
|
||||
*/
|
||||
|
||||
void TaskScheduler::SetWorkerCount(unsigned int workerCount)
|
||||
{
|
||||
#ifdef NAZARA_CORE_SAFE
|
||||
@@ -62,12 +93,22 @@ namespace Nz
|
||||
s_workerCount = workerCount;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Uninitializes the TaskScheduler class
|
||||
*/
|
||||
|
||||
void TaskScheduler::Uninitialize()
|
||||
{
|
||||
if (TaskSchedulerImpl::IsInitialized())
|
||||
TaskSchedulerImpl::Uninitialize();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Waits for tasks to be done
|
||||
*
|
||||
* \remark Produce a NazaraError if the class is not initialized
|
||||
*/
|
||||
|
||||
void TaskScheduler::WaitForTasks()
|
||||
{
|
||||
if (!Initialize())
|
||||
@@ -79,6 +120,15 @@ namespace Nz
|
||||
TaskSchedulerImpl::WaitForTasks();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds a task on the pending list
|
||||
*
|
||||
* \param taskFunctor Functor represeting a task to be done
|
||||
*
|
||||
* \remark Produce a NazaraError if the class is not initialized
|
||||
* \remark A task containing a call on this class is undefined behaviour
|
||||
*/
|
||||
|
||||
void TaskScheduler::AddTaskFunctor(Functor* taskFunctor)
|
||||
{
|
||||
if (!Initialize())
|
||||
|
||||
Reference in New Issue
Block a user