24#ifndef MYSQL_SCHEDULER_THREAD_POOL_H
25#define MYSQL_SCHEDULER_THREAD_POOL_H
28#include <condition_variable>
32#include <system_error>
47template <
class T, std::
size_t t_queue_size = 8192>
67 Thread_pool(
unsigned int thread_num = std::thread::hardware_concurrency(),
73 [[nodiscard]]
bool init();
Allocator using a Memory_resource to do the allocation.
Definition: allocator.h:52
Bounded concurrent queue supporting multiple producers and consumers.
Definition: sync_bounded_queue.h:84
Wrapper to mysql thread, which matches interface of std::thread.
Definition: thread_srv.h:46
MySQL wrapper for a condition variable, template which may be specialized with a specific implementat...
Definition: thread_pool.h:48
void end_execution()
Notifies all threads to end execution in a gracious way.
Definition: thread_pool_impl.hpp:136
unsigned int m_instance_id
Instance id.
Definition: thread_pool.h:127
bool init()
Initializes the thread pool by starting worker threads.
Definition: thread_pool_impl.hpp:47
void deinit()
Deinitializes the thread pool and joins all worker threads.
Definition: thread_pool_impl.hpp:72
unsigned int m_workers_num
The number of threads in the thread pool.
Definition: thread_pool.h:125
mysql::concurrency::Stage_key St_key
Definition: thread_pool.h:58
Queue_type m_tasks
Enqueued, ready to be executed tasks.
Definition: thread_pool.h:123
bool m_initialized
Whether init() completed successfully.
Definition: thread_pool.h:131
void run_worker(unsigned int thread_id)
Function executed by each thread.
Definition: thread_pool_impl.hpp:99
std::vector< Thread, Thread_allocator > m_workers
Thread container.
Definition: thread_pool.h:118
Thread_pool(unsigned int thread_num=std::thread::hardware_concurrency(), unsigned int instance_id=0, Thread_pool_psi psi_params={})
Constructs a thread pool.
Definition: thread_pool_impl.hpp:31
Thread_pool_psi m_psi
PSI parameters.
Definition: thread_pool.h:129
std::size_t size() const
Obtains worker pool size.
Definition: thread_pool_impl.hpp:144
mysql::concurrency::Thread_key Th_key
Definition: thread_pool.h:59
std::size_t queue_size() const
Get an estimation of number of elements in the worker queue.
Definition: thread_pool_impl.hpp:94
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.
Definition: thread_pool.h:121
virtual ~Thread_pool()
Destructor.
Definition: thread_pool_impl.hpp:131
std::packaged_task< T(unsigned int)> Task_type
Runnable task type, future is obtained by the caller.
Definition: thread_pool.h:53
std::string print_queue_state() const
Prints worker queue state, debug function.
Definition: thread_pool_impl.hpp:89
void enqueue(Task_type &&task)
Enqueues task for execution.
Definition: thread_pool_impl.hpp:84
Thread_pool(Thread_pool &&) noexcept=delete
static bool has_creation_error(const Thread &thread)
Checks whether worker thread construction failed.
Definition: thread_pool_impl.hpp:149
#define T
Definition: jit_executor_value.cc:373
static my_thread_id thread_id
Definition: my_thr_init.cc:60
PSI_stage_key Stage_key
Definition: stage_srv.h:35
std::thread Thread
Definition: thread_stl.h:42
PSI_thread_key Thread_key
Definition: thread_srv.h:43
Definition: base_dependency_tracker.h:41
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
Define std::hash<Gtid>.
Definition: gtid.h:355
std::unordered_map< Key, Value, Hash, Key_equal, ut::allocator< std::pair< const Key, Value > > > unordered_map
Definition: ut0new.h:2748
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2724
Instrumentation helpers for conditions.
Thread_pool instrumentation parameters, packed into this structure to simplify construction of a Thre...
Definition: thread_pool_psi.h:38