8 #ifndef META_OCEAN_BASE_WORKER_POOL_H
9 #define META_OCEAN_BASE_WORKER_POOL_H
79 inline Worker* worker()
const;
100 inline Worker* operator()()
const;
106 explicit inline operator bool()
const;
135 inline size_t capacity();
141 inline size_t size();
169 inline ScopedWorker conditionalScopedWorker(
const bool condition);
207 size_t capacity_ = 2;
215 *
this = std::move(
object);
236 if (worker_ !=
nullptr)
249 worker_ =
object.worker_;
250 object.worker_ =
nullptr;
261 inline WorkerPool::ScopedWorker::operator bool()
const
263 return worker_ !=
nullptr;
This class implements a recursive lock object.
Definition: Lock.h:31
This class implements a scoped lock object for recursive lock objects.
Definition: Lock.h:135
This template class is the base class for all singleton objects.
Definition: Singleton.h:71
static WorkerPool & get()
Returns a reference to the unique object.
Definition: Singleton.h:115
size_t size() const
Returns the size of this vector.
Definition: StaticVector.h:340
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
Definition of scoped worker object.
Definition: WorkerPool.h:48
ScopedWorker & operator=(ScopedWorker &&object) noexcept
Move a scoped worker object.
Definition: WorkerPool.h:243
ScopedWorker(const ScopedWorker &scopedWorker)=delete
Disabled copy constructor.
Worker * operator()() const
Returns the internal worker object.
Definition: WorkerPool.h:256
Worker * worker() const
Returns the internal worker object.
Definition: WorkerPool.h:229
ScopedWorker & operator=(const ScopedWorker &scopedWorker)=delete
Disabled copy operator.
~ScopedWorker()
Destructs a scoped worker object and unlocks the internal worker object automatically.
Definition: WorkerPool.h:224
ScopedWorker()=default
Creates an empty scoped worker object.
void release()
Explicitly releases the object and does not wait until the scope ends.
Definition: WorkerPool.h:234
This class implements a pool holding worker objects for individual use.
Definition: WorkerPool.h:26
Worker * lock()
Tries to lock a worker to be used for individual worker.
bool setCapacity(const size_t workers)
Defines the maximal number of worker objects existing concurrently.
Workers freeWorkers_
Vector holding the currently not-used worker objects.
Definition: WorkerPool.h:201
size_t capacity()
Returns the maximal number of worker objects allowed inside this pool.
Definition: WorkerPool.h:266
size_t capacity_
Maximal pool capacity, with range [1, infinity)
Definition: WorkerPool.h:207
Lock lock_
Lock for the entire pool.
Definition: WorkerPool.h:210
ScopedWorker scopedWorker()
Returns a scoped object holding the real worker if available.
void unlock(Worker *worker)
Unlocks a previously locked worker object to make it available for other users.
~WorkerPool()
Destructs a worker pool.
size_t size()
Returns the number of currently existing worker objects in this pool.
Definition: WorkerPool.h:273
Workers usedWorkers_
Vector holding the currently used worker objects.
Definition: WorkerPool.h:204
friend class ScopedWorker
Definition: WorkerPool.h:28
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
WorkerPool()=default
Creates a new worker pool and initializes the maximal worker capacity to 2.
std::unique_ptr< Worker > UniqueWorker
Definition of a unique pointer holding a Worker object.
Definition: WorkerPool.h:35
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15