ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::threadmodel::DWManager Class Reference

Description:

Attention
This class belongs to module ALib ThreadModel, which is not in a stable and consistent state, yet. Also this type is considered experimental.

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.

Inheritance diagram for alib::threadmodel::DWManager:
[legend]
Collaboration diagram for alib::threadmodel::DWManager:
[legend]

Public Method Index:

ALIB_DLL void Add (DedicatedWorker &thread)
 
MonoAllocatorGetAllocator ()
 
PoolAllocatorGetPoolAllocator ()
 
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)
 
- Public Method Index: inherited from alib::singletons::Singleton< DWManager >
virtual ~Singleton ()
 Virtual destructor.
 
- Public Method Index: inherited from alib::threads::Lock
 ~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)
 
- Public Method Index: inherited from alib::lang::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 alib::threads::Lock
std::mutex mutex
 

Private Method Index:

ALIB_DLL DWManager ()
 Constructor.
 

Additional Inherited Members

- Public Static Method Index: inherited from alib::singletons::Singleton< DWManager >
static DWManagerGetSingleton ()
 
- Public Field Index: inherited from alib::threads::Lock
DbgLockAsserter Dbg
 The debug tool instance.
 

Friends And Related Entity Details:

◆ singletons::Singleton< DWManager >

friend class singletons::Singleton< DWManager >
friend

Definition at line 8 of file dedicatedworker.inl.

Field Details:

◆ ma

MonoAllocator alib::threadmodel::DWManager::ma
protected

Mono allocator. Used for commands and by DedicatedWorkers.

Definition at line 32 of file dedicatedworker.inl.

◆ pool

PoolAllocator alib::threadmodel::DWManager::pool
protected

Pool allocator. Used for command objects.

Definition at line 35 of file dedicatedworker.inl.

◆ workers

List<MonoAllocator, DedicatedWorker*> alib::threadmodel::DWManager::workers
protected

The list of workers.

Definition at line 38 of file dedicatedworker.inl.

Constructor(s) / Destructor Details:

◆ DWManager()

alib::threadmodel::DWManager::DWManager ( )
private

Constructor.

Definition at line 35 of file dedicatedworker.cpp.

Method Details:

◆ Add()

void alib::threadmodel::DWManager::Add ( DedicatedWorker & thread)

Adds and starts a worker.

Parameters
threadThe thread to add.

Definition at line 49 of file dedicatedworker.cpp.

Here is the call graph for this function:

◆ GetAllocator()

MonoAllocator & alib::threadmodel::DWManager::GetAllocator ( )
inline

Allows access to the singleton instances' allocator.

Returns
The monotonic allocator.

Definition at line 47 of file dedicatedworker.inl.

◆ GetPoolAllocator()

PoolAllocator & alib::threadmodel::DWManager::GetPoolAllocator ( )
inline

Allows access to the singleton instances' pool allocator.

Returns
The pool allocator.

Definition at line 51 of file dedicatedworker.inl.

◆ Remove()

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.

Parameters
threadThe thread to remove.
stopPriorityThe priority passed to DedicatedWorker::ScheduleStop. Use Lowest (the default) to ensure that all other commands are duly executed before exiting.
Returns
true if the thread was found and removed, false otherwise.

Definition at line 60 of file dedicatedworker.cpp.

Here is the call graph for this function:

◆ RemoveAll()

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.

Parameters
stopPriorityThe 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.

Here is the call graph for this function:

◆ WaitForAllIdle()

bool alib::threadmodel::DWManager::WaitForAllIdle ( Ticks::Duration timeout,
Ticks::Duration dbgWarnAfter )

Waits until all threads are idle.

Parameters
timeoutThe maximum time to wait.
dbgWarnAfterThe 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.
Returns
true if all threads are idle, false otherwise.

Definition at line 96 of file dedicatedworker.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: