This singleton-class manages worker threads of type DedicatedWorker. Such threads are started by adding them to the singleton instance of this type and are stopped with removal.
DedicatedWorkers use this type's PoolAllocator to create and dispose Job objects and derived types are allowed to allocate resources in its MonoAllocator.
Definition at line 24 of file dedicatedworker.inl.
Public Method Index: | |
ALIB_DLL void | Add (DedicatedWorker &thread) |
MonoAllocator & | GetAllocator () |
PoolAllocator & | GetPoolAllocator () |
ALIB_DLL bool | Remove (DedicatedWorker &thread, Priority stopPriority=Priority::Lowest) |
ALIB_DLL void | RemoveAll (Priority stopPriority=Priority::Lowest) |
ALIB_DLL bool | WaitForAllIdle (Ticks::Duration timeout, Ticks::Duration dbgWarnAfter) |
![]() | |
virtual | ~Singleton () |
Virtual destructor. | |
![]() | |
~Lock () override | |
Destructor. With debug-compilations, asserts that this lock is not acquired. | |
ALIB_DLL void | Acquire (ALIB_DBG_TAKE_CI) |
virtual ALIB_DLL bool | DCSIsAcquired () const override |
virtual ALIB_DLL bool | DCSIsSharedAcquired () const override |
ALIB_DLL void | Release (ALIB_DBG_TAKE_CI) |
ALIB_DLL bool | TryAcquire (ALIB_DBG_TAKE_CI) |
![]() | |
virtual | ~AssociatedLock () |
Virtual Destructor. | |
Protected Field Index: | |
MonoAllocator | ma |
Mono allocator. Used for commands and by DedicatedWorkers. | |
PoolAllocator | pool |
Pool allocator. Used for command objects. | |
List< MonoAllocator, DedicatedWorker * > | workers |
The list of workers. | |
![]() | |
std::mutex | mutex |
Private Method Index: | |
ALIB_DLL | DWManager () |
Constructor. | |
Additional Inherited Members | |
![]() | |
static DWManager & | GetSingleton () |
![]() | |
DbgLockAsserter | Dbg |
The debug tool instance. | |
|
friend |
Definition at line 8 of file dedicatedworker.inl.
|
protected |
Mono allocator. Used for commands and by DedicatedWorkers.
Definition at line 32 of file dedicatedworker.inl.
|
protected |
Pool allocator. Used for command objects.
Definition at line 35 of file dedicatedworker.inl.
|
protected |
The list of workers.
Definition at line 38 of file dedicatedworker.inl.
|
private |
Constructor.
Definition at line 35 of file dedicatedworker.cpp.
void alib::threadmodel::DWManager::Add | ( | DedicatedWorker & | thread | ) |
Adds and starts a worker.
thread | The thread to add. |
Definition at line 49 of file dedicatedworker.cpp.
|
inline |
Allows access to the singleton instances' allocator.
Definition at line 47 of file dedicatedworker.inl.
|
inline |
Allows access to the singleton instances' pool allocator.
Definition at line 51 of file dedicatedworker.inl.
bool alib::threadmodel::DWManager::Remove | ( | DedicatedWorker & | thread, |
Priority | stopPriority = Priority::Lowest ) |
Remove a previously added worker. The thread is stopped by invoking DedicatedWorker::ScheduleStop using the given priority. It is waited until it exits, and finally the thread is joined.
With debug-compilations, an ALib warning is raised every second if the thread does not stop.
thread | The thread to remove. |
stopPriority | The priority passed to DedicatedWorker::ScheduleStop. Use Lowest (the default) to ensure that all other commands are duly executed before exiting. |
true
if the thread was found and removed, false
otherwise. Definition at line 60 of file dedicatedworker.cpp.
void alib::threadmodel::DWManager::RemoveAll | ( | Priority | stopPriority = Priority::Lowest | ) |
Stops execution and terminates all workers by invoking DedicatedWorker::ScheduleStop.
After this method has been invoked, no further commands should be scheduled, even if the given priority equals Lowest. This should be assured by the using code.
With debug-compilations, an ALib warning is raised every second until all managed threads stopped.
stopPriority | The priority passed to DedicatedWorker::ScheduleStop. Use Lowest (the default) to ensure that all other commands are duly executed before exiting. |
Definition at line 146 of file dedicatedworker.cpp.
bool alib::threadmodel::DWManager::WaitForAllIdle | ( | Ticks::Duration | timeout, |
Ticks::Duration | dbgWarnAfter ) |
Waits until all threads are idle.
timeout | The maximum time to wait. |
dbgWarnAfter | The time after which a warning message will be printed to the debug log if the timeout was reached. This parameter is only available in debug-compilations and thus should be passed using macro ALIB_DBG. |
true
if all threads are idle, false
otherwise. Definition at line 96 of file dedicatedworker.cpp.