Ocean
Ocean::ThreadPoolSingleton Class Reference

This class wraps the ThreadPool into a singleton for global usage. More...

Inheritance diagram for Ocean::ThreadPoolSingleton:

Protected Member Functions

 ThreadPoolSingleton ()
 Protected default constructor. More...
 
- Protected Member Functions inherited from Ocean::Singleton< ThreadPoolSingleton >
 Singleton ()=default
 Default constructor. More...
 
- Protected Member Functions inherited from Ocean::ThreadPool
void threadRun () override
 Thread run function. More...
 
- Protected Member Functions inherited from Ocean::Thread
 Thread (const Thread &thread)=delete
 Disabled copy constructor. More...
 
void createThread ()
 Creates the thread itself. More...
 
void destroyThread ()
 Destroys the thread itself. More...
 
void stopThreadExplicitly (const unsigned int timeout=5000u)
 Tries to stop the thread gracefully. More...
 
Threadoperator= (const Thread &thread)=delete
 The disabled assign operator. More...
 
 Thread (const std::string &name=std::string())
 Creates a new thread object. More...
 
 Thread (const unsigned int randomNumberSeedValue, const std::string &name=std::string())
 Creates a new thread object. More...
 
virtual ~Thread ()
 Destructs a thread object. More...
 
bool startThread ()
 Starts the thread. More...
 
void stopThread ()
 Informs the thread to stop. More...
 
bool terminateThread ()
 Terminates the thread. More...
 
bool joinThread (const unsigned int timeout=(unsigned int)(-1))
 Waits until this thread has been stopped. More...
 
bool shouldThreadStop () const
 Returns whether this thread should stop. More...
 
bool isThreadInvokedToStart () const
 Returns whether this thread has been invoked to start immediately. More...
 
bool isThreadActive () const
 Returns whether this thread is active. More...
 

Friends

class Singleton< ThreadPoolSingleton >
 

Additional Inherited Members

- Public Types inherited from Ocean::ThreadPool
using Function = std::function< void()>
 Definition of a caller function without return parameter. More...
 
- Public Member Functions inherited from Ocean::ThreadPool
 ThreadPool ()=default
 Creates a new thread pool object. More...
 
 ~ThreadPool () override
 Destructs a thread pool. More...
 
size_t capacity () const
 Returns the maximal number of thread objects allowed inside this pool. More...
 
size_t size () const
 Returns the number of currently busy/active threads in this pool. More...
 
bool setCapacity (const size_t capacity)
 Defines the maximal number of thread objects existing concurrently. More...
 
bool invoke (Function &&function)
 Invokes a function on one of the free threads of this pool. More...
 
size_t pending () const
 Returns the number of pending functions. More...
 
bool isEmpty () const
 Returns whether the ThreadPool has completed all jobs that have been submitted. More...
 
- Static Public Member Functions inherited from Ocean::Singleton< ThreadPoolSingleton >
static ThreadPoolSingletonget ()
 Returns a reference to the unique object. More...
 
- Protected Types inherited from Ocean::ThreadPool
using UniquePoolThread = std::unique_ptr< PoolThread >
 Definition of a unique pointer holding a pool thread. More...
 
using PoolThreads = std::vector< UniquePoolThread >
 Definition of a vector holding pool threads. More...
 
using FunctionQueue = std::queue< Function >
 Definition of a queue holding functions. More...
 
- Protected Types inherited from Ocean::Thread
typedef std::pair< pthread_t, bool > TimedJoinPair
 Definition of a pair holding a thread id and a boolean state. More...
 
enum  ThreadPriority {
  PRIORITY_IDLE , PRIORTY_BELOW_NORMAL , PRIORTY_NORMAL , PRIORTY_ABOVE_NORMAL ,
  PRIORTY_HIGH , PRIORTY_REALTIME
}
 Definition of different thread priority values. More...
 
- Static Protected Member Functions inherited from Ocean::Thread
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...
 
- Protected Attributes inherited from Ocean::ThreadPool
PoolThreads busyPoolThreads_
 The busy pool threads. More...
 
PoolThreads idlePoolThreads_
 The idle pool threads. More...
 
FunctionQueue pendingFunctions_
 The pending functions. More...
 
size_t capacity_ = 2
 Maximal pool capacity, with range [1, infinity) More...
 
size_t poolThreadIdCounter_ = 0
 The counter for pool thread ids. More...
 
Lock lock_
 Pool lock. More...
 

Detailed Description

This class wraps the ThreadPool into a singleton for global usage.

Use the standard ThreadPool in case a singleton is not sufficient.

See also
ThreadPool.

Constructor & Destructor Documentation

◆ ThreadPoolSingleton()

Ocean::ThreadPoolSingleton::ThreadPoolSingleton ( )
protected

Protected default constructor.

Friends And Related Function Documentation

◆ Singleton< ThreadPoolSingleton >

friend class Singleton< ThreadPoolSingleton >
friend

The documentation for this class was generated from the following file: