8 #ifndef META_OCEAN_BASE_THREAD_POOL_H
9 #define META_OCEAN_BASE_THREAD_POOL_H
62 inline bool isBusy()
const;
120 inline size_t capacity()
const;
126 inline size_t size()
const;
146 inline size_t pending()
const;
167 size_t capacity_ = 2;
170 size_t poolThreadIdCounter_ = 0;
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 class implements a signal.
Definition: Signal.h:31
This template class is the base class for all singleton objects.
Definition: Singleton.h:71
This class implements a thread.
Definition: Thread.h:115
This class implements one thread of this thread pool.
Definition: ThreadPool.h:44
void invoke(Function &&function)
Sets the thread function.
PoolThread(const std::string &name)
Creates a new thread object.
Lock lock_
Thread lock.
Definition: ThreadPool.h:86
void threadRun() override
Thread run function.
bool isBusy() const
Returns whether this thread is currently busy.
Definition: ThreadPool.h:196
Signal signal_
Internal signal handling the internal thread execution.
Definition: ThreadPool.h:80
Function function_
The function that is invoked in this thread.
Definition: ThreadPool.h:83
~PoolThread() override
Destructs a thread object.
This class implements a pool holding re-usable thread objects for individual use.
Definition: ThreadPool.h:30
size_t capacity_
Maximal pool capacity, with range [1, infinity)
Definition: ThreadPool.h:167
size_t size() const
Returns the number of currently busy/active threads in this pool.
Definition: ThreadPool.h:209
FunctionQueue pendingFunctions_
The pending functions.
Definition: ThreadPool.h:164
size_t capacity() const
Returns the maximal number of thread objects allowed inside this pool.
Definition: ThreadPool.h:203
ThreadPool()=default
Creates a new thread pool object.
PoolThreads idlePoolThreads_
The idle pool threads.
Definition: ThreadPool.h:161
Lock lock_
Pool lock.
Definition: ThreadPool.h:173
std::function< void()> Function
Definition of a caller function without return parameter.
Definition: ThreadPool.h:36
std::queue< Function > FunctionQueue
Definition of a queue holding functions.
Definition: ThreadPool.h:102
bool invoke(Function &&function)
Invokes a function on one of the free threads of this pool.
bool setCapacity(const size_t capacity)
Defines the maximal number of thread objects existing concurrently.
~ThreadPool() override
Destructs a thread pool.
void threadRun() override
Thread run function.
PoolThreads busyPoolThreads_
The busy pool threads.
Definition: ThreadPool.h:158
size_t pending() const
Returns the number of pending functions.
Definition: ThreadPool.h:216
std::vector< UniquePoolThread > PoolThreads
Definition of a vector holding pool threads.
Definition: ThreadPool.h:97
std::unique_ptr< PoolThread > UniquePoolThread
Definition of a unique pointer holding a pool thread.
Definition: ThreadPool.h:92
This class wraps the ThreadPool into a singleton for global usage.
Definition: ThreadPool.h:185
ThreadPoolSingleton()
Protected default constructor.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15