MySQL 8.4.2
Source Code Documentation
|
This class maintains THD object of all registered threads. More...
#include <mysqld_thd_manager.h>
Public Member Functions | |
void | set_unit_test () |
Internally used to bypass code. More... | |
void | add_thd (THD *thd) |
Adds THD to global THD list. More... | |
void | remove_thd (THD *thd) |
Removes THD from global THD list. More... | |
int | get_num_thread_running () const |
Retrieves thread running statistic variable. More... | |
void | inc_thread_running () |
Increments thread running statistic variable. More... | |
void | dec_thread_running () |
Decrements thread running statistic variable. More... | |
ulonglong | get_num_thread_created () const |
Retrieves thread created statistic variable. More... | |
void | inc_thread_created () |
Increments thread created statistic variable. More... | |
my_thread_id | get_new_thread_id () |
Returns an unused thread id. More... | |
void | release_thread_id (my_thread_id thread_id) |
Releases a thread id so that it can be reused. More... | |
my_thread_id | get_thread_id () const |
Retrieves thread id counter value. More... | |
void | set_thread_id_counter (my_thread_id new_id) |
Sets thread id counter value. More... | |
void | wait_till_no_thd () |
Waits until all THDs are removed from global THD lists (all partitions). More... | |
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 THD list partition. More... | |
void | do_for_all_thd (Do_THD_Impl *func) |
This function calls func() for all THDs in all THD list partitions. More... | |
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. More... | |
THD_ptr | find_thd (Find_THD_Impl *func) |
Returns a THD_ptr containing first THD for which operator() returns true. More... | |
THD_ptr | find_thd (Find_thd_with_id *func) |
Static Public Member Functions | |
static Global_THD_manager * | get_instance () |
Retrieves singleton instance. More... | |
static bool | is_initialized () |
Checks if the singleton is not already deinitialized. More... | |
static bool | create_instance () |
Initializes the thd manager. More... | |
static void | destroy_instance () |
Destroys the singleton instance. More... | |
static uint | get_thd_count () |
Retrieves total number of items in global THD lists (all partitions). More... | |
Static Public Attributes | |
static const my_thread_id | reserved_thread_id = 0 |
Value for thread_id reserved for THDs which does not have an assigned value yet. More... | |
static std::atomic< uint > | atomic_global_thd_count {0U} |
static const int | NUM_PARTITIONS = 8 |
Private Types | |
typedef Prealloced_array< THD *, 60 > | THD_array |
typedef Prealloced_array< my_thread_id, 1000 > | Thread_id_array |
Private Member Functions | |
Global_THD_manager () | |
~Global_THD_manager () | |
Private Attributes | |
THD_array | thd_list [NUM_PARTITIONS] |
Thread_id_array | thread_ids |
mysql_cond_t | COND_thd_list [NUM_PARTITIONS] |
mysql_mutex_t | LOCK_thd_list [NUM_PARTITIONS] |
mysql_mutex_t | LOCK_thd_remove [NUM_PARTITIONS] |
mysql_mutex_t | LOCK_thread_ids |
std::atomic< int > | atomic_num_thread_running |
std::atomic< ulonglong > | atomic_thread_created |
my_thread_id | thread_id_counter |
bool | unit_test |
Static Private Attributes | |
static Global_THD_manager * | thd_manager = nullptr |
Friends | |
void | thd_lock_thread_count () |
void | thd_unlock_thread_count () |
This class maintains THD object of all registered threads.
It provides interface to perform functions such as find, count, perform some action for each THD object in the list.
It also provide mutators for inserting, and removing an element: add_thd() inserts a THD into the set, and increments the counter. remove_thd() removes a THD from the set, and decrements the counter. Method remove_thd() also broadcasts COND_thd_list.
|
private |
|
private |
|
private |
|
private |
void Global_THD_manager::add_thd | ( | THD * | thd | ) |
Adds THD to global THD list.
thd | THD object |
|
static |
Initializes the thd manager.
Must be called before get_instance() can be used.
|
inline |
Decrements thread running statistic variable.
|
static |
Destroys the singleton instance.
void Global_THD_manager::do_for_all_thd | ( | Do_THD_Impl * | func | ) |
This function calls func() for all THDs in all THD list partitions.
func | Object of class which overrides operator() |
void Global_THD_manager::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 THD list partition.
It acquires LOCK_thd_remove to prevent removal of the THD.
func | Object of class which overrides operator() |
void Global_THD_manager::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.
func | Object of class which overrides operator() |
n | number of elements we want to call func for |
THD_ptr Global_THD_manager::find_thd | ( | Find_THD_Impl * | func | ) |
Returns a THD_ptr containing first THD for which operator() returns true.
func | Object of class which overrides operator() |
THD_ptr{THD*} | When matching THD is found. |
THD_ptr{nullptr} | When THD is not found. |
THD_ptr Global_THD_manager::find_thd | ( | Find_thd_with_id * | func | ) |
|
inlinestatic |
Retrieves singleton instance.
my_thread_id Global_THD_manager::get_new_thread_id | ( | ) |
Returns an unused thread id.
|
inline |
Retrieves thread created statistic variable.
|
inline |
Retrieves thread running statistic variable.
|
inlinestatic |
Retrieves total number of items in global THD lists (all partitions).
|
inline |
Retrieves thread id counter value.
|
inline |
Increments thread created statistic variable.
|
inline |
Increments thread running statistic variable.
|
inlinestatic |
Checks if the singleton is not already deinitialized.
void Global_THD_manager::release_thread_id | ( | my_thread_id | thread_id | ) |
Releases a thread id so that it can be reused.
Note that this is done automatically by remove_thd().
void Global_THD_manager::remove_thd | ( | THD * | thd | ) |
Removes THD from global THD list.
thd | THD object |
void Global_THD_manager::set_thread_id_counter | ( | my_thread_id | new_id | ) |
Sets thread id counter value.
Only used in testing for now.
new_id | The next ID to hand out (if it's unused). |
|
inline |
Internally used to bypass code.
It enables unit test scripts to create dummy THD object for testing.
void Global_THD_manager::wait_till_no_thd | ( | ) |
Waits until all THDs are removed from global THD lists (all partitions).
In other words, get_thd_count() to become zero.
|
friend |
|
friend |
|
static |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
static |
|
static |
Value for thread_id reserved for THDs which does not have an assigned value yet.
get_new_thread_id() will never return this value.
|
private |
|
staticprivate |
|
private |
|
private |
|
private |