This class implements a pool holding worker objects for individual use.
More...
This class implements a pool holding worker objects for individual use.
- See also
- Worker.
◆ UniqueWorker
Definition of a unique pointer holding a Worker object.
◆ Workers
Definition of a static vector holding worker objects.
◆ WorkerPool()
Ocean::WorkerPool::WorkerPool |
( |
| ) |
|
|
privatedefault |
Creates a new worker pool and initializes the maximal worker capacity to 2.
◆ ~WorkerPool()
Ocean::WorkerPool::~WorkerPool |
( |
| ) |
|
|
private |
◆ capacity()
size_t Ocean::WorkerPool::capacity |
( |
| ) |
|
|
inline |
Returns the maximal number of worker objects allowed inside this pool.
- Returns
- Maximal worker capacity, with range [1, 10], 2 by default
◆ conditionalScopedWorker()
Returns a scoped object holding the real worker if a given condition is 'True' and if a worker is available.
The scoped object guarantees the existence of the real worker (if provided in the moment this function is called) as long as the scoped object exists.
This function allows to apply something like:
static WorkerPool & get()
Returns a reference to the unique object.
Definition: Singleton.h:115
ScopedWorker conditionalScopedWorker(const bool condition)
Returns a scoped object holding the real worker if a given condition is 'True' and if a worker is ava...
Definition: WorkerPool.h:280
- Parameters
-
condition | True, to get a scoped worker with real worker object (if available); False, to get an empty scoped worker |
- Returns
- Object holding the worker if available, otherwise the object will be empty
◆ lock()
Worker* Ocean::WorkerPool::lock |
( |
| ) |
|
|
private |
Tries to lock a worker to be used for individual worker.
Beware: This worker object must be unlocked after usage.
- Returns
- Worker object if available, otherwise nullptr
- See also
- unlock().
◆ scopedWorker()
Returns a scoped object holding the real worker if available.
The scoped object guarantees the existence of the real worker (if available in the moment this function is called) as long as the scoped object exists.
- Returns
- Object holding the worker if available, otherwise the object will be empty
◆ setCapacity()
bool Ocean::WorkerPool::setCapacity |
( |
const size_t |
workers | ) |
|
Defines the maximal number of worker objects existing concurrently.
- Parameters
-
workers | Maximal number of worker objects to be allowed inside this pool, with range [capacity(), 10] |
- Returns
- True, if succeeded
◆ size()
size_t Ocean::WorkerPool::size |
( |
| ) |
|
|
inline |
Returns the number of currently existing worker objects in this pool.
- Returns
- Worker count, with range [0, capacity()]
◆ unlock()
void Ocean::WorkerPool::unlock |
( |
Worker * |
worker | ) |
|
|
private |
Unlocks a previously locked worker object to make it available for other users.
Beware: To not use an unlocked worker object anymore.
- Parameters
-
worker | The worker to be unlocked |
◆ ScopedWorker
◆ Singleton< WorkerPool >
◆ capacity_
size_t Ocean::WorkerPool::capacity_ = 2 |
|
private |
Maximal pool capacity, with range [1, infinity)
◆ freeWorkers_
Workers Ocean::WorkerPool::freeWorkers_ |
|
private |
Vector holding the currently not-used worker objects.
◆ lock_
Lock Ocean::WorkerPool::lock_ |
|
private |
Lock for the entire pool.
◆ usedWorkers_
Workers Ocean::WorkerPool::usedWorkers_ |
|
private |
Vector holding the currently used worker objects.
The documentation for this class was generated from the following file: