8#ifndef META_OCEAN_BASE_WORKER_POOL_H
9#define META_OCEAN_BASE_WORKER_POOL_H
79 inline Worker* worker()
const;
85 inline void release();
100 inline Worker* operator()()
const;
106 explicit inline operator bool()
const;
135 static constexpr size_t maximalCapacity();
141 inline size_t capacity();
147 inline size_t size();
175 inline ScopedWorker conditionalScopedWorker(
const bool condition);
213 size_t capacity_ = 2;
221 *
this = std::move(
object);
242 if (worker_ !=
nullptr)
255 worker_ =
object.worker_;
256 object.worker_ =
nullptr;
267inline WorkerPool::ScopedWorker::operator bool()
const
269 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:147
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
static constexpr size_t capacity()
Returns the capacity of this buffer.
Definition StaticBuffer.h:232
size_t size() const
Returns the size of this vector.
Definition StaticVector.h:390
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:249
ScopedWorker(const ScopedWorker &scopedWorker)=delete
Disabled copy constructor.
Worker * operator()() const
Returns the internal worker object.
Definition WorkerPool.h:262
ScopedWorker & operator=(const ScopedWorker &scopedWorker)=delete
Disabled copy operator.
Worker * worker() const
Returns the internal worker object.
Definition WorkerPool.h:235
~ScopedWorker()
Destructs a scoped worker object and unlocks the internal worker object automatically.
Definition WorkerPool.h:230
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:240
This class implements a pool holding worker objects for individual use.
Definition WorkerPool.h:26
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:207
size_t capacity()
Returns the maximal number of worker objects allowed inside this pool.
Definition WorkerPool.h:277
static constexpr size_t maximalCapacity()
Returns the highest capacity this pool can be configured with.
Definition WorkerPool.h:272
size_t capacity_
Maximal pool capacity, with range [1, infinity)
Definition WorkerPool.h:213
Lock lock_
Lock for the entire pool.
Definition WorkerPool.h:216
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.
Worker * lock()
Tries to lock a worker to be used for individual worker.
size_t size()
Returns the number of currently existing worker objects in this pool.
Definition WorkerPool.h:284
Workers usedWorkers_
Vector holding the currently used worker objects.
Definition WorkerPool.h:210
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:291
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