Asposecpplib

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

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

Static Public Member Functions

static 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

void Worker ()
 Worker thread function. More...
 
void AddWorkers (uint32_t amount)
 Adds worker threads to the pool. More...
 
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()

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

Constructor.

◆ ~ThreadPoolImpl()

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

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

Member Function Documentation

◆ AddWorkers()

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

Adds worker threads to the pool.

Parameters
amountNumber of worker threads to create.

◆ DelWorkers()

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

Deletes worker threads from the pool.

Parameters
amountNumber of worker threads to delete.

◆ GetAvailableThreads()

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 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()

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()

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()

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

Joins all owned threads. Waits infinitely.

◆ QueueUserWorkItem()

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()

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()

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()

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.