This class implements a pool holding re-usable thread objects for individual use.
More...
|
using | Function = std::function< void()> |
| Definition of a caller function without return parameter. More...
|
|
|
static void | sleep (unsigned int ms) |
| Sleeps the calling thread for a given time. More...
|
|
static void | giveUp () |
| Gives up the remaining thread time. More...
|
|
static ThreadId | currentThreadId () |
| Returns the thread id of the current (calling) thread. More...
|
|
static ThreadPriority | threadPriority () |
| Returns the priority of the current thread. More...
|
|
static bool | setThreadPriority (const ThreadPriority priority) |
| Sets the priority of the current thread. More...
|
|
template<typename TObject , typename TExpectedValue > |
static bool | waitForValue (TObject &object, const TExpectedValue &expectedValue, const double timeout=-1.0) |
| Waits until an object/variable has an expected value. More...
|
|
template<typename TObject , typename TExpectedValue > |
static bool | waitForValue (TObject &object, const TExpectedValue &expectedValue, TemporaryScopedLock &temporaryScopedLock, const double timeout=-1.0) |
| Waits until an object/variable has an expected value. More...
|
|
static int | pthread_timedjoin_np (pthread_t thread, void **retval, const struct timespec *abstime) |
| Implements a thread join function with timeout value. More...
|
|
This class implements a pool holding re-usable thread objects for individual use.
This class is not a singleton, use ThreadPoolSingleton in case a singleton is sufficient.
- See also
- ThreadPoolSingleton, Scheduler, TaskQueue.
◆ Function
Definition of a caller function without return parameter.
◆ FunctionQueue
Definition of a queue holding functions.
◆ PoolThreads
Definition of a vector holding pool threads.
◆ UniquePoolThread
Definition of a unique pointer holding a pool thread.
◆ ThreadPool()
Ocean::ThreadPool::ThreadPool |
( |
| ) |
|
|
default |
Creates a new thread pool object.
◆ ~ThreadPool()
Ocean::ThreadPool::~ThreadPool |
( |
| ) |
|
|
override |
◆ capacity()
size_t Ocean::ThreadPool::capacity |
( |
| ) |
const |
|
inline |
Returns the maximal number of thread objects allowed inside this pool.
- Returns
- Maximal thread capacity, with range [1, infinity); 2 by default
◆ invoke()
bool Ocean::ThreadPool::invoke |
( |
Function && |
function | ) |
|
Invokes a function on one of the free threads of this pool.
- Parameters
-
function | The function that will be invoked by a free thread |
- Returns
- True, if the function will be invoked by a free thread, otherwise no free thread was available
◆ isEmpty()
bool Ocean::ThreadPool::isEmpty |
( |
| ) |
const |
|
inline |
Returns whether the ThreadPool has completed all jobs that have been submitted.
- Returns
- True, if the results of size() and pending() are atomically both 0
◆ pending()
size_t Ocean::ThreadPool::pending |
( |
| ) |
const |
|
inline |
Returns the number of pending functions.
- Returns
- The number of pending functions which have not been executed yet as the pool is at capacity, with range [0, infinity)
◆ setCapacity()
bool Ocean::ThreadPool::setCapacity |
( |
const size_t |
capacity | ) |
|
Defines the maximal number of thread objects existing concurrently.
- Parameters
-
capacity | Maximal number of thread objects to be allowed inside this pool, with range (1, infinity) |
- Returns
- True, if succeeded
◆ size()
size_t Ocean::ThreadPool::size |
( |
| ) |
const |
|
inline |
Returns the number of currently busy/active threads in this pool.
- Returns
- Thread number, with range [0, infinity)
◆ threadRun()
void Ocean::ThreadPool::threadRun |
( |
| ) |
|
|
overrideprotectedvirtual |
◆ busyPoolThreads_
◆ capacity_
size_t Ocean::ThreadPool::capacity_ = 2 |
|
protected |
Maximal pool capacity, with range [1, infinity)
◆ idlePoolThreads_
◆ lock_
Lock Ocean::ThreadPool::lock_ |
|
mutableprotected |
◆ pendingFunctions_
◆ poolThreadIdCounter_
size_t Ocean::ThreadPool::poolThreadIdCounter_ = 0 |
|
protected |
The counter for pool thread ids.
The documentation for this class was generated from the following file: