Thread pool internal data. This is a singleton type with memory management done by access function(s). You should never create instances of it directly. More...

Public Member Functions

ASPOSECPP_SHARED_API bool QueueUserWorkItem (WaitCallback callback, const System::SharedPtr< System::Object > &state)
 Adds work item to queue. More...
 
ASPOSECPP_SHARED_API void GetAvailableThreads (int &wt, int &cpt)
 Gets number of available threads. More...
 
ASPOSECPP_SHARED_API void GetMaxThreads (int &wt, int &cpt)
 Gets maximal number of concurrent threads. More...
 
ASPOSECPP_SHARED_API void GetMinThreads (int &wt, int &cpt)
 Gets minimal number of threads being created by pool. More...
 
ASPOSECPP_SHARED_API bool SetMaxThreads (int wt, int cpt)
 Sets number of threads owned by pool. More...
 
ASPOSECPP_SHARED_API bool SetMinThreads (int wt, int cpt)
 Sets minimal number of threads owned by pool. More...
 
ASPOSECPP_SHARED_API ThreadPoolImpl ()
 Constructor. More...
 
ASPOSECPP_SHARED_API ~ThreadPoolImpl ()
 Destructor. Joins all threads if they were not terminated yet. More...
 
ASPOSECPP_SHARED_API void JoinAll ()
 Joins all owned threads. Waits infinitely. More...
 

Static Public Member Functions

static ASPOSECPP_SHARED_API bool & GetInitialized ()
 Gets initialization state singleton. More...
 

Protected Types

typedef std::pair< WaitCallback, System::SharedPtr< System::Object > > Job
 Structure that keeps job callback and parameter to be executed. More...
 

Protected Member Functions

ASPOSECPP_SHARED_API void Worker ()
 Worker thread function. More...
 
ASPOSECPP_SHARED_API void AddWorkers (uint32_t amount)
 Adds worker threads to the pool. More...
 
ASPOSECPP_SHARED_API void DelWorkers (uint32_t amount)
 Deletes worker threads from the pool. More...
 

Protected Attributes

std::uint32_t m_max_threads
 Maximal allowed number of threads to exist simultaneously in the pool. More...
 
std::uint32_t m_min_threads
 Minimal allowed number of threads to be created on request. More...
 
std::mutex m_mutex
 Mutex that blocks thread pool task queue. More...
 
std::condition_variable m_cv
 Condition variable used to keep executor threads waiting. More...
 
std::queue< Jobm_queue
 Jobs queue. More...
 

Detailed Description

Thread pool internal data. This is a singleton type with memory management done by access function(s). You should never create instances of it directly.

Member Typedef Documentation

◆ Job

Structure that keeps job callback and parameter to be executed.

Constructor & Destructor Documentation

◆ ThreadPoolImpl()

ASPOSECPP_SHARED_API System::Threading::ThreadPoolImpl::ThreadPoolImpl ( )

Constructor.

◆ ~ThreadPoolImpl()

ASPOSECPP_SHARED_API System::Threading::ThreadPoolImpl::~ThreadPoolImpl ( )

Destructor. Joins all threads if they were not terminated yet.

Member Function Documentation

◆ AddWorkers()

ASPOSECPP_SHARED_API void System::Threading::ThreadPoolImpl::AddWorkers ( uint32_t  amount)
protected

Adds worker threads to the pool.

Parameters
amountNumber of worker threads to create.

◆ DelWorkers()

ASPOSECPP_SHARED_API void System::Threading::ThreadPoolImpl::DelWorkers ( uint32_t  amount)
protected

Deletes worker threads from the pool.

Parameters
amountNumber of worker threads to delete.

◆ GetAvailableThreads()

ASPOSECPP_SHARED_API void System::Threading::ThreadPoolImpl::GetAvailableThreads ( int &  wt,
int &  cpt 
)

Gets number of available threads.

Parameters
wtReference to variable to store number of awailable worker threads.
cptReference to variable to store number of awailable IO threads.

◆ GetInitialized()

static ASPOSECPP_SHARED_API bool& System::Threading::ThreadPoolImpl::GetInitialized ( )
static

Gets initialization state singleton.

Returns
Reference to variable that holds true if initialization was done already and false otherwise.

◆ GetMaxThreads()

ASPOSECPP_SHARED_API void System::Threading::ThreadPoolImpl::GetMaxThreads ( int &  wt,
int &  cpt 
)

Gets maximal number of concurrent threads.

Parameters
wtReference to variable to store maximal number of awailable worker threads.
cptReference to variable to store maximal number of awailable IO threads.

◆ GetMinThreads()

ASPOSECPP_SHARED_API void System::Threading::ThreadPoolImpl::GetMinThreads ( int &  wt,
int &  cpt 
)

Gets minimal number of threads being created by pool.

Parameters
wtReference to variable to store minimal number of awailable worker threads.
cptReference to variable to store minimal number of awailable IO threads.

◆ JoinAll()

ASPOSECPP_SHARED_API void System::Threading::ThreadPoolImpl::JoinAll ( )

Joins all owned threads. Waits infinitely.

◆ QueueUserWorkItem()

ASPOSECPP_SHARED_API bool System::Threading::ThreadPoolImpl::QueueUserWorkItem ( WaitCallback  callback,
const System::SharedPtr< System::Object > &  state 
)

Adds work item to queue.

Parameters
callbackCallback function to execute.
stateCallback function argument.
Returns
Always returns true.

◆ SetMaxThreads()

ASPOSECPP_SHARED_API bool System::Threading::ThreadPoolImpl::SetMaxThreads ( int  wt,
int  cpt 
)

Sets number of threads owned by pool.

Parameters
wtMaximal number of worker threads.
cptMaximal number of IO threads.
Returns
True if parameters were accepted, false otherwise.

◆ SetMinThreads()

ASPOSECPP_SHARED_API bool System::Threading::ThreadPoolImpl::SetMinThreads ( int  wt,
int  cpt 
)

Sets minimal number of threads owned by pool.

Parameters
wtMinimal number of worker threads.
cptMinimal number of IO threads.
Returns
True if parameters were accepted, false otherwise.

◆ Worker()

ASPOSECPP_SHARED_API void System::Threading::ThreadPoolImpl::Worker ( )
protected

Worker thread function.

Member Data Documentation

◆ m_cv

std::condition_variable System::Threading::ThreadPoolImpl::m_cv
protected

Condition variable used to keep executor threads waiting.

◆ m_max_threads

std::uint32_t System::Threading::ThreadPoolImpl::m_max_threads
protected

Maximal allowed number of threads to exist simultaneously in the pool.

◆ m_min_threads

std::uint32_t System::Threading::ThreadPoolImpl::m_min_threads
protected

Minimal allowed number of threads to be created on request.

◆ m_mutex

std::mutex System::Threading::ThreadPoolImpl::m_mutex
protected

Mutex that blocks thread pool task queue.

◆ m_queue

std::queue<Job> System::Threading::ThreadPoolImpl::m_queue
protected

Jobs queue.