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 43 of file dedicatedworker.hpp.
#include <dedicatedworker.hpp>
Public Method Index: | |
ALIB_API void | Add (DedicatedWorker &thread) |
MonoAllocator & | GetAllocator () |
PoolAllocator & | GetPoolAllocator () |
ALIB_API bool | Remove (DedicatedWorker &thread, Priority stopPriority=Priority::Lowest) |
ALIB_API void | RemoveAll (Priority stopPriority=Priority::Lowest) |
ALIB_API bool | WaitForAllIdle (Ticks::Duration timeout, Ticks::Duration dbgWarnAfter) |
Public Method Index: inherited from Singleton< DWManager > | |
virtual | ~Singleton () |
Virtual destructor. | |
Public Method Index: inherited from Lock | |
~Lock () override | |
Destructor. With debug-compilations, asserts that this lock is not acquired. | |
ALIB_API void | Acquire (ALIB_DBG_TAKE_CI) |
virtual ALIB_API bool | DCSIsAcquired () const override |
virtual ALIB_API bool | DCSIsSharedAcquired () const override |
ALIB_API void | Release (ALIB_DBG_TAKE_CI) |
ALIB_API bool | TryAcquire (ALIB_DBG_TAKE_CI) |
Public Method Index: inherited from DbgCriticalSections::AssociatedLock | |
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. | |
Protected Field Index: inherited from Lock | |
std::mutex | mutex |
Private Method Index: | |
ALIB_API | DWManager () |
Constructor. | |
Additional Inherited Members | |
Public Static Method Index: inherited from Singleton< DWManager > | |
static DWManager & | GetSingleton () |
Public Field Index: inherited from Lock | |
DbgLockAsserter | Dbg |
The debug tool instance. | |
Protected Static Field Index: inherited from Singleton< DWManager > | |
static DWManager * | singleton |
A pointer to the one and only singleton. | |
|
friend |
Definition at line 1 of file dedicatedworker.hpp.
|
protected |
Mono allocator. Used for commands and by DedicatedWorkers.
Definition at line 51 of file dedicatedworker.hpp.
|
protected |
Pool allocator. Used for command objects.
Definition at line 54 of file dedicatedworker.hpp.
|
protected |
The list of workers.
Definition at line 57 of file dedicatedworker.hpp.
|
private |
Constructor.
Definition at line 48 of file dedicatedworker.cpp.
void Add | ( | DedicatedWorker & | thread | ) |
Adds and starts a worker.
thread | The thread to add. |
Definition at line 62 of file dedicatedworker.cpp.
|
inline |
Allows access to the singleton instances' allocator.
Definition at line 66 of file dedicatedworker.hpp.
|
inline |
Allows access to the singleton instances' pool allocator.
Definition at line 70 of file dedicatedworker.hpp.
bool 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 73 of file dedicatedworker.cpp.
void 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 157 of file dedicatedworker.cpp.
bool 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 111 of file dedicatedworker.cpp.