24#ifndef MYSQLD_THD_MANAGER_INCLUDED
25#define MYSQLD_THD_MANAGER_INCLUDED
Base class to perform actions on all thds in the thd list.
Definition: mysqld_thd_manager.h:52
virtual ~Do_THD_Impl()=default
virtual void operator()(THD *)=0
Base class to find specific thd from the thd list.
Definition: mysqld_thd_manager.h:64
virtual ~Find_THD_Impl()=default
virtual bool operator()(THD *thd)=0
Override this operator to provide implementation to find specific thd.
Callback function used by kill_one_thread and timer_notify functions to find "thd" based on the threa...
Definition: mysqld_thd_manager.h:83
bool operator()(THD *thd) override
Override this operator to provide implementation to find specific thd.
Definition: mysqld_thd_manager.cc:61
const bool m_daemon_allowed
Definition: mysqld_thd_manager.h:90
Find_thd_with_id(my_thread_id value, bool daemon_allowed=false)
Definition: mysqld_thd_manager.h:85
const my_thread_id m_thread_id
Definition: mysqld_thd_manager.h:89
This class maintains THD object of all registered threads.
Definition: mysqld_thd_manager.h:201
std::atomic< int > atomic_num_thread_running
Definition: mysqld_thd_manager.h:386
~Global_THD_manager()
Definition: mysqld_thd_manager.cc:191
void add_thd(THD *thd)
Adds THD to global THD list.
Definition: mysqld_thd_manager.cc:218
mysql_mutex_t LOCK_thd_remove[NUM_PARTITIONS]
Definition: mysqld_thd_manager.h:381
static std::atomic< uint > atomic_global_thd_count
Definition: mysqld_thd_manager.h:356
static Global_THD_manager * thd_manager
Definition: mysqld_thd_manager.h:366
void inc_thread_running()
Increments thread running statistic variable.
Definition: mysqld_thd_manager.h:265
void do_for_all_thd_copy(Do_THD_Impl *func)
This function calls func() for all THDs in every thd list partition after taking local copy of the TH...
Definition: mysqld_thd_manager.cc:291
my_thread_id thread_id_counter
Definition: mysqld_thd_manager.h:392
Prealloced_array< THD *, 60 > THD_array
Definition: mysqld_thd_manager.h:369
friend void thd_lock_thread_count()
Definition: mysqld_thd_manager.cc:371
mysql_mutex_t LOCK_thd_list[NUM_PARTITIONS]
Definition: mysqld_thd_manager.h:379
my_thread_id get_thread_id() const
Retrieves thread id counter value.
Definition: mysqld_thd_manager.h:300
void do_for_all_thd(Do_THD_Impl *func)
This function calls func() for all THDs in all THD list partitions.
Definition: mysqld_thd_manager.cc:314
void set_unit_test()
Internally used to bypass code.
Definition: mysqld_thd_manager.h:240
bool unit_test
Definition: mysqld_thd_manager.h:395
void release_thread_id(my_thread_id thread_id)
Releases a thread id so that it can be reused.
Definition: mysqld_thd_manager.cc:264
static const my_thread_id reserved_thread_id
Value for thread_id reserved for THDs which does not have an assigned value yet.
Definition: mysqld_thd_manager.h:208
int get_num_thread_running() const
Retrieves thread running statistic variable.
Definition: mysqld_thd_manager.h:260
Thread_id_array thread_ids
Definition: mysqld_thd_manager.h:374
void dec_thread_running()
Decrements thread running statistic variable.
Definition: mysqld_thd_manager.h:270
my_thread_id get_new_thread_id()
Returns an unused thread id.
Definition: mysqld_thd_manager.cc:255
static bool is_initialized()
Checks if the singleton is not already deinitialized.
Definition: mysqld_thd_manager.h:221
static void destroy_instance()
Destroys the singleton instance.
Definition: mysqld_thd_manager.cc:213
THD_array thd_list[NUM_PARTITIONS]
Definition: mysqld_thd_manager.h:370
void do_for_first_n_thd(Do_THD_Impl *func, uint n)
This function calls func() for all first "n" THDs across all THD list partitions.
Definition: mysqld_thd_manager.cc:322
void set_thread_id_counter(my_thread_id new_id)
Sets thread id counter value.
Definition: mysqld_thd_manager.cc:273
std::atomic< ulonglong > atomic_thread_created
Definition: mysqld_thd_manager.h:389
ulonglong get_num_thread_created() const
Retrieves thread created statistic variable.
Definition: mysqld_thd_manager.h:277
void wait_till_no_thd()
Waits until all THDs are removed from global THD lists (all partitions).
Definition: mysqld_thd_manager.cc:279
friend void thd_unlock_thread_count()
Definition: mysqld_thd_manager.cc:376
void remove_thd(THD *thd)
Removes THD from global THD list.
Definition: mysqld_thd_manager.cc:232
Global_THD_manager()
Definition: mysqld_thd_manager.cc:151
mysql_mutex_t LOCK_thread_ids
Definition: mysqld_thd_manager.h:383
static uint get_thd_count()
Retrieves total number of items in global THD lists (all partitions).
Definition: mysqld_thd_manager.h:312
void inc_thread_created()
Increments thread created statistic variable.
Definition: mysqld_thd_manager.h:282
static Global_THD_manager * get_instance()
Retrieves singleton instance.
Definition: mysqld_thd_manager.h:213
mysql_cond_t COND_thd_list[NUM_PARTITIONS]
Definition: mysqld_thd_manager.h:376
Prealloced_array< my_thread_id, 1000 > Thread_id_array
Definition: mysqld_thd_manager.h:373
static bool create_instance()
Initializes the thd manager.
Definition: mysqld_thd_manager.cc:207
static const int NUM_PARTITIONS
Definition: mysqld_thd_manager.h:359
THD_ptr find_thd(Find_THD_Impl *func)
Returns a THD_ptr containing first THD for which operator() returns true.
Definition: mysqld_thd_manager.cc:335
This class encapsulates THD instance, controls access to the actual THD.
Definition: mysqld_thd_manager.h:98
THD * get()
Access underlying THD instance.
Definition: mysqld_thd_manager.h:145
bool operator==(std::nullptr_t) const
Compare underlying THD pointer value with the "nullptr".
Definition: mysqld_thd_manager.h:166
~THD_ptr()
Destructor to release underlying THD instance's control and release mutex THD::LOCK_thd_data.
Definition: mysqld_thd_manager.h:124
THD_ptr(THD_ptr const &)=delete
Delete copy constructor, THD_ptr copy is not allowed.
bool operator!=(std::nullptr_t) const
Compare underlying THD pointer value with the "nullptr".
Definition: mysqld_thd_manager.h:177
THD * m_underlying
Definition: mysqld_thd_manager.h:187
THD * operator->()
Access underlying THD instance.
Definition: mysqld_thd_manager.h:150
THD_ptr()=default
Default class constructor.
THD & operator*()
Access underlying THD instance.
Definition: mysqld_thd_manager.h:155
bool operator!=(THD const *thd_ptr) const
Compare this instance with other THD_ptr instance.
Definition: mysqld_thd_manager.h:183
THD * release()
Release underlying THD instance's control and release THD::LOCK_thd_data.
Definition: mysqld_thd_manager.cc:120
bool operator==(THD const *thd_ptr) const
Compare this instance with other THD_ptr instance.
Definition: mysqld_thd_manager.h:172
THD_ptr & operator=(THD_ptr const &)=delete
Delete copy operator, THD_ptr copy is not allowed.
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
static my_thread_id thread_id
Definition: my_thr_init.cc:63
uint32 my_thread_id
Definition: my_thread_local.h:34
Instrumentation helpers for conditions.
ABI for instrumented mutexes.
void thd_lock_thread_count()
Definition: mysqld_thd_manager.cc:371
void thd_unlock_thread_count()
Definition: mysqld_thd_manager.cc:376
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
uint32_t new_id()
Create a new (hopefully unique) ID.
Definition: xcom_base.cc:1786
int n
Definition: xcom_base.cc:509