![]() |
MySQL 26.7.0
Source Code Documentation
|
MySQL wrapper for a condition variable, template which may be specialized with a specific implementation of a condition variable, e.g. More...
#include <thread_pool.h>
Public Types | |
| using | Thread = concurrency::Thread |
| Thread type. More... | |
| using | Task_type = std::packaged_task< T(unsigned int)> |
| Runnable task type, future is obtained by the caller. More... | |
| using | Queue_type = concurrency::Sync_bounded_queue< Task_type, t_queue_size > |
| Queue type used to synchronize a thread supplying task to this thread pool and worker threads. More... | |
| using | St_key = mysql::concurrency::Stage_key |
| using | Th_key = mysql::concurrency::Thread_key |
| using | Thread_allocator = mysql::allocators::Allocator< Thread > |
Public Member Functions | |
| Thread_pool (unsigned int thread_num=std::thread::hardware_concurrency(), unsigned int instance_id=0, Thread_pool_psi psi_params={}) | |
| Constructs a thread pool. More... | |
| bool | init () |
| Initializes the thread pool by starting worker threads. More... | |
| void | deinit () |
| Deinitializes the thread pool and joins all worker threads. More... | |
| void | enqueue (Task_type &&task) |
| Enqueues task for execution. More... | |
| virtual | ~Thread_pool () |
| Destructor. More... | |
| void | end_execution () |
| Notifies all threads to end execution in a gracious way. More... | |
| Thread_pool (Thread_pool &&) noexcept=delete | |
| Thread_pool & | operator= (Thread_pool &&) noexcept=delete |
| Thread_pool (const Thread_pool &)=delete | |
| Thread_pool & | operator= (const Thread_pool &)=delete |
| std::string | print_queue_state () const |
| Prints worker queue state, debug function. More... | |
| std::size_t | queue_size () const |
| Get an estimation of number of elements in the worker queue. More... | |
| std::size_t | size () const |
| Obtains worker pool size. More... | |
Private Member Functions | |
| void | run_worker (unsigned int thread_id) |
| Function executed by each thread. More... | |
Static Private Member Functions | |
| static bool | has_creation_error (const Thread &thread) |
| Checks whether worker thread construction failed. More... | |
Private Attributes | |
| std::vector< Thread, Thread_allocator > | m_workers |
| Thread container. More... | |
| std::unordered_map< unsigned int, std::atomic< bool > > | m_end_execution |
| Variable indicating the end of execution, allows threads to stop in a gracious way. More... | |
| Queue_type | m_tasks |
| Enqueued, ready to be executed tasks. More... | |
| unsigned int | m_workers_num |
| The number of threads in the thread pool. More... | |
| unsigned int | m_instance_id {0} |
| Instance id. More... | |
| Thread_pool_psi | m_psi |
| PSI parameters. More... | |
| bool | m_initialized {false} |
| Whether init() completed successfully. More... | |
MySQL wrapper for a condition variable, template which may be specialized with a specific implementation of a condition variable, e.g.
MySQL condition variable, and satisfying the following requirements:
| using mysql::scheduler::Thread_pool< T, t_queue_size >::Queue_type = concurrency::Sync_bounded_queue<Task_type, t_queue_size> |
Queue type used to synchronize a thread supplying task to this thread pool and worker threads.
Worker threads are consumers of this queue type
| using mysql::scheduler::Thread_pool< T, t_queue_size >::St_key = mysql::concurrency::Stage_key |
| using mysql::scheduler::Thread_pool< T, t_queue_size >::Task_type = std::packaged_task<T(unsigned int)> |
Runnable task type, future is obtained by the caller.
| using mysql::scheduler::Thread_pool< T, t_queue_size >::Th_key = mysql::concurrency::Thread_key |
| using mysql::scheduler::Thread_pool< T, t_queue_size >::Thread = concurrency::Thread |
Thread type.
| using mysql::scheduler::Thread_pool< T, t_queue_size >::Thread_allocator = mysql::allocators::Allocator<Thread> |
| mysql::scheduler::Thread_pool< T, t_queue_size >::Thread_pool | ( | unsigned int | thread_num = std::thread::hardware_concurrency(), |
| unsigned int | instance_id = 0, |
||
| Thread_pool_psi | psi_params = {} |
||
| ) |
Constructs a thread pool.
| thread_num | Numbers of threads in a thread pool, set as default to the number of concurrent threads supported by the implementation |
| instance_id | THP will gather statistics for this instance id |
| psi_params | PSI parameters |
|
virtual |
Destructor.
|
deletenoexcept |
|
delete |
| void mysql::scheduler::Thread_pool< T, t_queue_size >::deinit |
Deinitializes the thread pool and joins all worker threads.
| void mysql::scheduler::Thread_pool< T, t_queue_size >::end_execution |
Notifies all threads to end execution in a gracious way.
When finished, Thread_pool object is ready to be destroyed. This function is called in destructor.
| void mysql::scheduler::Thread_pool< T, t_queue_size >::enqueue | ( | Task_type && | task | ) |
Enqueues task for execution.
| task | Functor to be executed by the thread pool |
|
staticprivate |
Checks whether worker thread construction failed.
| thread | Worker thread object. |
| bool mysql::scheduler::Thread_pool< T, t_queue_size >::init |
Initializes the thread pool by starting worker threads.
| false | Success |
| true | Failure |
|
delete |
|
deletenoexcept |
| std::string mysql::scheduler::Thread_pool< T, t_queue_size >::print_queue_state |
Prints worker queue state, debug function.
| std::size_t mysql::scheduler::Thread_pool< T, t_queue_size >::queue_size |
Get an estimation of number of elements in the worker queue.
|
private |
Function executed by each thread.
| std::size_t mysql::scheduler::Thread_pool< T, t_queue_size >::size |
Obtains worker pool size.
|
private |
Variable indicating the end of execution, allows threads to stop in a gracious way.
|
private |
Whether init() completed successfully.
|
private |
Instance id.
|
private |
PSI parameters.
|
private |
Enqueued, ready to be executed tasks.
|
private |
Thread container.
|
private |
The number of threads in the thread pool.