22 #include "scheduler.h"
23 #include "sql_connect.h"
24 #include "scheduler.h"
25 #include "sql_callback.h"
26 #include "global_threads.h"
27 #include "mysql/thread_pool_priv.h"
33 static bool no_threads_end(THD *thd,
bool put_in_cache)
35 thd_release_resources(thd);
36 dec_connection_count();
40 remove_global_thread(thd);
51 init_new_connection_handler_thread,
52 #ifndef EMBEDDED_LIBRARY
53 handle_connection_in_main_thread,
56 #endif // EMBEDDED_LIBRARY
64 #ifndef EMBEDDED_LIBRARY
69 init_new_connection_handler_thread,
70 create_thread_to_handle_connection,
74 one_thread_per_connection_end,
77 #endif // EMBEDDED_LIBRARY
90 static void scheduler_wait_lock_begin(
void) {
91 MYSQL_CALLBACK(thread_scheduler,
92 thd_wait_begin, (current_thd, THD_WAIT_TABLE_LOCK));
95 static void scheduler_wait_lock_end(
void) {
96 MYSQL_CALLBACK(thread_scheduler, thd_wait_end, (current_thd));
99 static void scheduler_wait_sync_begin(
void) {
100 MYSQL_CALLBACK(thread_scheduler,
101 thd_wait_begin, (current_thd, THD_WAIT_TABLE_LOCK));
104 static void scheduler_wait_sync_end(
void) {
105 MYSQL_CALLBACK(thread_scheduler, thd_wait_end, (current_thd));
117 static void scheduler_init() {
118 thr_set_lock_wait_callback(scheduler_wait_lock_begin,
119 scheduler_wait_lock_end);
120 thr_set_sync_wait_callback(scheduler_wait_sync_begin,
121 scheduler_wait_sync_end);
128 #ifndef EMBEDDED_LIBRARY
129 void one_thread_per_connection_scheduler()
132 one_thread_per_connection_scheduler_functions.max_threads= max_connections;
133 thread_scheduler= &one_thread_per_connection_scheduler_functions;
141 void one_thread_scheduler()
144 thread_scheduler= &one_thread_scheduler_functions;
157 thd_scheduler::thd_scheduler()
158 : m_psi(NULL), data(NULL)
163 thd_scheduler::~thd_scheduler()
168 static uint saved_thread_handling;
173 DBUG_ASSERT(scheduler != 0);
175 if (scheduler == NULL)
178 saved_thread_scheduler= thread_scheduler;
179 saved_thread_handling= thread_handling;
180 thread_scheduler= scheduler;
182 thread_handling= SCHEDULER_TYPES_COUNT;
188 int my_thread_scheduler_reset()
190 DBUG_ASSERT(saved_thread_scheduler != NULL);
192 if (saved_thread_scheduler == NULL)
195 thread_scheduler= saved_thread_scheduler;
196 thread_handling= saved_thread_handling;
197 saved_thread_scheduler= 0;