2#ifndef _aspose_system_threading_thread_pool_h_
3#define _aspose_system_threading_thread_pool_h_
7#include <condition_variable>
8#include <system/object.h>
9#include <system/multicast_delegate.h>
10#include <system/shared_ptr.h>
12namespace System {
namespace Threading {
73 std::condition_variable
m_cv;
75 typedef std::pair<WaitCallback, System::SharedPtr<System::Object>>
Job;
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:62
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
Thread pool API allowing it pushing jobs into queue to be read by pool of worker threads....
Definition: thread_pool.h:155
static ThreadPoolImpl & GetInstance()
Implementation instance that holds list of jobs and other parameters.
static void GetAvailableThreads(int &wt, int &cpt)
Gets number of available threads.
static void JoinAllThreads()
Joins all owned threads. Waits infinitely.
static void GetMinThreads(int &wt, int &cpt)
Gets minimal number of threads being created by pool.
static bool QueueUserWorkItem(WaitCallback callback)
Puts work item into queue which is present with callback with no parameter.
ThreadPool(const ThreadPool &)=delete
No copying.
void operator=(const ThreadPool &)=delete
No copying.
static bool SetMinThreads(int wt, int cpt)
Sets minimal number of threads owned by pool.
static bool QueueUserWorkItem(WaitCallback callback, const System::SharedPtr< System::Object > &state)
Puts work item into queue which is present with callback with no parameter.
static bool SetMaxThreads(int wt, int cpt)
Sets number of threads owned by pool.
static void GetMaxThreads(int &wt, int &cpt)
Gets maximal number of concurrent threads.
Thread pool internal data. This is a singleton type with memory management done by access function(s)...
Definition: thread_pool.h:23
void GetMaxThreads(int &wt, int &cpt)
Gets maximal number of concurrent threads.
std::uint32_t m_min_threads
Minimal allowed number of threads to be created on request.
Definition: thread_pool.h:69
ThreadPoolImpl()
Constructor.
void GetMinThreads(int &wt, int &cpt)
Gets minimal number of threads being created by pool.
std::uint32_t m_max_threads
Maximal allowed number of threads to exist simultaneously in the pool.
Definition: thread_pool.h:67
std::pair< WaitCallback, System::SharedPtr< System::Object > > Job
Structure that keeps job callback and parameter to be executed.
Definition: thread_pool.h:75
std::mutex m_mutex
Mutex that blocks thread pool task queue.
Definition: thread_pool.h:71
std::condition_variable m_cv
Condition variable used to keep executor threads waiting.
Definition: thread_pool.h:73
static bool & GetInitialized()
Gets initialization state singleton.
void JoinAll()
Joins all owned threads. Waits infinitely.
std::queue< Job > m_queue
Jobs queue.
Definition: thread_pool.h:77
void AddWorkers(uint32_t amount)
Adds worker threads to the pool.
~ThreadPoolImpl()
Destructor. Joins all threads if they were not terminated yet.
bool SetMaxThreads(int wt, int cpt)
Sets number of threads owned by pool.
bool SetMinThreads(int wt, int cpt)
Sets minimal number of threads owned by pool.
void Worker()
Worker thread function.
void DelWorkers(uint32_t amount)
Deletes worker threads from the pool.
bool QueueUserWorkItem(WaitCallback callback, const System::SharedPtr< System::Object > &state)
Adds work item to queue.
void GetAvailableThreads(int &wt, int &cpt)
Gets number of available threads.
System::MulticastDelegate< void(System::SharedPtr< System::Object >)> WaitCallback
Callback item to be executed once there is a spot.
Definition: thread_pool.h:15
Definition: db_command.h:9