From 4e4081bb40c2c38bff131c3f4f0dbf7374bc580b Mon Sep 17 00:00:00 2001 From: Mikael Ronstrom Date: Thu, 20 Jan 2011 18:24:48 +0100 Subject: BUG#59549, fix compiler error on Windows, step 2 --- sql/sql_class.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index c058e66df97..efa125acb2e 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -493,7 +493,7 @@ bool Drop_table_error_handler::handle_condition(THD *thd, THD::THD() - :Statement(&main_lex, &main_mem_root, CONVENTIONAL_EXECUTION, + :Statement(&main_lex, &main_mem_root, ES_CONVENTIONAL_EXECUTION, /* statement id */ 0), rli_fake(0), user_time(0), in_sub_stmt(0), -- cgit v1.2.1 From c89e1f80936e6de7e0cef5553f2cfcea010f9188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20Ronstr=C3=B6m?= Date: Thu, 10 Feb 2011 19:38:36 +0100 Subject: more fixes of scheduler interface changes --- sql/sql_class.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index f2a41bee707..8d00b981533 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -217,6 +217,16 @@ bool foreign_key_prefix(Key *a, Key *b) ** Thread specific functions ****************************************************************************/ +void* thd_get_scheduler(THD *thd) +{ + return thd->scheduler.data; +} + +PSI_thread* thd_get_psi(THD *thd) +{ + return thd->scheduler.m_psi; +} + /* The following functions form part of the C plugin API */ -- cgit v1.2.1 From cb33511af6845bd9774ac79352a7f46a36359bde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20Ronstr=C3=B6m?= Date: Thu, 10 Feb 2011 19:47:46 +0100 Subject: Added setters to scheduler interface --- sql/sql_class.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 8d00b981533..3067b86d5e1 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -217,16 +217,26 @@ bool foreign_key_prefix(Key *a, Key *b) ** Thread specific functions ****************************************************************************/ -void* thd_get_scheduler(THD *thd) +void *thd_get_scheduler_data(THD *thd) { return thd->scheduler.data; } -PSI_thread* thd_get_psi(THD *thd) +void thd_set_scheduler_data(THD *thd, void *data) +{ + thd->scheduler.data= data; +} + +PSI_thread *thd_get_psi(THD *thd) { return thd->scheduler.m_psi; } +void thd_set_psi(THD *thd, PSI_thread *psi) +{ + thd->scheduler.m_psi= psi; +} + /* The following functions form part of the C plugin API */ -- cgit v1.2.1 From b04b333e2590052e62a8837ce13e5287c401ef84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20Ronstr=C3=B6m?= Date: Wed, 16 Feb 2011 19:30:02 +0100 Subject: Defined private interface to THD variables, first step to plugin API --- sql/sql_class.cc | 196 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 3067b86d5e1..43e55f27502 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -217,26 +217,222 @@ bool foreign_key_prefix(Key *a, Key *b) ** Thread specific functions ****************************************************************************/ +/** + Get reference to scheduler data object + + @param thd THD object + + @retval Scheduler data object on THD +*/ void *thd_get_scheduler_data(THD *thd) { return thd->scheduler.data; } +/** + Set reference to Scheduler data object for THD object + + @param thd THD object + @param psi Scheduler data object to set on THD +*/ void thd_set_scheduler_data(THD *thd, void *data) { thd->scheduler.data= data; } +/** + Get reference to Performance Schema object for THD object + + @param thd THD object + + @retval Performance schema object for thread on THD +*/ PSI_thread *thd_get_psi(THD *thd) { return thd->scheduler.m_psi; } +/** + Set reference to Performance Schema object for THD object + + @param thd THD object + @param psi Performance schema object for thread +*/ void thd_set_psi(THD *thd, PSI_thread *psi) { thd->scheduler.m_psi= psi; } +/** + Set the state on connection to killed + + @param thd THD object +*/ +void thd_set_killed(THD *thd) +{ + thd->killed= THD::KILL_CONNECTION; +} + +/** + Clear errors from the previous THD + + @param thd THD object +*/ +void thd_clear_errors(THD *thd) +{ + my_errno= 0; + thd->mysys_var->abort= 0; +} + +/** + Set thread stack in THD object + + @param thd Thread object + @param stack_start Start of stack to set in THD object +*/ +void thd_set_thread_stack(THD *thd, char *stack_start) +{ + thd->thread_stack= stack_start; +} + +/** + Lock connection data for the set of connections this connection + belongs to + + @param thd THD object +*/ +void thd_lock_connection_data(THD *thd) +{ + (void)thd; + mysql_mutex_lock(&LOCK_thread_count); +} + +/** + Lock connection data for the set of connections this connection + belongs to + + @param thd THD object +*/ +void thd_unlock_connection_data(THD *thd) +{ + (void)thd; + mysql_cond_broadcast(&COND_thread_count); + mysql_mutex_unlock(&LOCK_thread_count); +} + +/** + Close the socket used by this connection + + @param thd THD object +*/ +void thd_close_connection(THD *thd) +{ + if (thd->net.vio) + vio_close(thd->net.vio); +} + +/** + Get current THD object from thread local data + + @retval The THD object for the thread, NULL if not connection thread +*/ +THD *thd_get_current_thd() +{ + return current_thd; +} + +/** + Set up various THD data for a new connection + + thd_new_connection_setup + + @param thd THD object + @param stack_start Start of stack for connection +*/ +void thd_new_connection_setup(THD *thd, char *stack_start) +{ +#ifdef HAVE_PSI_INTERFACE + if (PSI_server) + thd_set_psi(thd, + PSI_server->new_thread(key_thread_one_connection, + thd, + thd_get_thread_id((MYSQL_THD)thd))); +#endif + thd->set_time(); + thd->prior_thr_create_utime= thd->thr_create_utime= thd->start_utime= + my_micro_time(); + threads.append(thd); + thd_unlock_connection_data(thd); + DBUG_PRINT("info", ("init new connection. thd: 0x%lx fd: %d", + (ulong)thd, thd->net.vio->sd)); + thd_set_thread_stack(thd, stack_start); +} + +/** + Lock data that needs protection in THD object + + @param thd THD object +*/ +void thd_lock_data(THD *thd) +{ + mysql_mutex_lock(&thd->LOCK_thd_data); +} + +/** + Unlock data that needs protection in THD object + + @param thd THD object +*/ +void thd_unlock_data(THD *thd) +{ + mysql_mutex_unlock(&thd->LOCK_thd_data); +} + +/** + Support method to check if connection has already started transcaction + + @param client_cntx Low level client context + + @retval TRUE if connection already started transaction +*/ +bool thd_is_transaction_active(THD *thd) +{ + return thd->transaction.is_active(); +} + +/** + Check if there is buffered data on the socket representing the connection + + @param thd THD object +*/ +int thd_connection_has_data(THD *thd) +{ + Vio *vio= thd->net.vio; + return vio->has_data(vio); +} + +/** + Set reading/writing on socket, used by SHOW PROCESSLIST + + @param thd THD object + @param val Value to set it to (0 or 1) +*/ +void thd_set_net_read_write(THD *thd, uint val) +{ + thd->net.reading_or_writing= val; +} + +/** + Set reference to mysys variable in THD object + + @param thd THD object + @param mysys_var Reference to set +*/ +void thd_set_mysys_var(THD *thd, st_my_thread_var *mysys_var) +{ + thd->set_mysys_var(mysys_var); +} + /* The following functions form part of the C plugin API */ -- cgit v1.2.1 From fef450b17fc3f87e11ae45dd8a8a1249b077b06c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20Ronstr=C3=B6m?= Date: Wed, 16 Feb 2011 20:38:35 +0100 Subject: More work on interfaces --- sql/sql_class.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 43e55f27502..39f80f2307d 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -433,6 +433,38 @@ void thd_set_mysys_var(THD *thd, st_my_thread_var *mysys_var) thd->set_mysys_var(mysys_var); } +/** + Get socket file descriptor for this connection + + @param thd THD object + + @retval Socket of the connection +*/ +my_socket thd_get_fd(THD *thd) +{ + return thd->net.vio->sd; +} + +/** + Get thread attributes for connection threads + + @retval Reference to thread attribute for connection threads +*/ +pthread_attr_t *get_connection_attrib(void) +{ + return &connection_attrib; +} + +/** + Get max number of connections + + @retval Max number of connections for MySQL Server +*/ +ulong get_max_connections(void) +{ + return max_connections; +} + /* The following functions form part of the C plugin API */ -- cgit v1.2.1 From 917da2749f1912c18ebeea08ce5a83a455807219 Mon Sep 17 00:00:00 2001 From: Mikael Ronstrom Date: Fri, 4 Mar 2011 13:17:58 +0100 Subject: Further review fixes --- sql/sql_class.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 39f80f2307d..3061cf9deda 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -742,7 +742,7 @@ bool Drop_table_error_handler::handle_condition(THD *thd, THD::THD() - :Statement(&main_lex, &main_mem_root, ES_CONVENTIONAL_EXECUTION, + :Statement(&main_lex, &main_mem_root, STMT_CONVENTIONAL_EXECUTION, /* statement id */ 0), rli_fake(0), user_time(0), in_sub_stmt(0), @@ -3550,7 +3550,7 @@ extern "C" void thd_pool_wait_end(MYSQL_THD thd); thd_wait_end MUST be called immediately after waking up again. */ -extern "C" void thd_wait_begin(MYSQL_THD thd, thd_wait_type wait_type) +extern "C" void thd_wait_begin(MYSQL_THD thd, int wait_type) { MYSQL_CALLBACK(thread_scheduler, thd_wait_begin, (thd, wait_type)); } @@ -3566,7 +3566,7 @@ extern "C" void thd_wait_end(MYSQL_THD thd) MYSQL_CALLBACK(thread_scheduler, thd_wait_end, (thd)); } #else -extern "C" void thd_wait_begin(MYSQL_THD thd, thd_wait_type wait_type) +extern "C" void thd_wait_begin(MYSQL_THD thd, int wait_type) { /* do NOTHING for the embedded library */ return; -- cgit v1.2.1 From 0db7bb2bfe5cdbb366245a9137d8fed11e7881b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20Ronstr=C3=B6m?= Date: Fri, 15 Apr 2011 12:57:59 +0200 Subject: Use C++ manner for unused param instead of C manner --- sql/sql_class.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 3061cf9deda..8f5d7f05033 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -301,9 +301,8 @@ void thd_set_thread_stack(THD *thd, char *stack_start) @param thd THD object */ -void thd_lock_connection_data(THD *thd) +void thd_lock_connection_data(THD *) { - (void)thd; mysql_mutex_lock(&LOCK_thread_count); } @@ -313,9 +312,8 @@ void thd_lock_connection_data(THD *thd) @param thd THD object */ -void thd_unlock_connection_data(THD *thd) +void thd_unlock_connection_data(THD *) { - (void)thd; mysql_cond_broadcast(&COND_thread_count); mysql_mutex_unlock(&LOCK_thread_count); } -- cgit v1.2.1 From cec8c6e7904a393f79563ff2f8fa6e2a04891374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20Ronstr=C3=B6m?= Date: Fri, 15 Apr 2011 13:00:59 +0200 Subject: Changed name to better reflect function logic in accordance with WL#5788 --- sql/sql_class.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 8f5d7f05033..21aed554ace 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -301,7 +301,7 @@ void thd_set_thread_stack(THD *thd, char *stack_start) @param thd THD object */ -void thd_lock_connection_data(THD *) +void thd_lock_thread_count(THD *) { mysql_mutex_lock(&LOCK_thread_count); } @@ -312,7 +312,7 @@ void thd_lock_connection_data(THD *) @param thd THD object */ -void thd_unlock_connection_data(THD *) +void thd_unlock_thread_count(THD *) { mysql_cond_broadcast(&COND_thread_count); mysql_mutex_unlock(&LOCK_thread_count); -- cgit v1.2.1 From 8486212a24baaa73a22fffbc01e61c6737443b46 Mon Sep 17 00:00:00 2001 From: Mikael Ronstrom Date: Wed, 20 Apr 2011 15:07:19 +0200 Subject: Fixed missing change of thd_unlock_connection_data to thd_unlock_thread_count --- sql/sql_class.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index dd245d6ccab..026166726b2 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -359,7 +359,7 @@ void thd_new_connection_setup(THD *thd, char *stack_start) thd->prior_thr_create_utime= thd->thr_create_utime= thd->start_utime= my_micro_time(); threads.append(thd); - thd_unlock_connection_data(thd); + thd_unlock_thread_count(thd); DBUG_PRINT("info", ("init new connection. thd: 0x%lx fd: %d", (ulong)thd, thd->net.vio->sd)); thd_set_thread_stack(thd, stack_start); -- cgit v1.2.1 From 359549beabcdafaa847dc41ef2566d414331f79d Mon Sep 17 00:00:00 2001 From: Mayank Prasad Date: Wed, 18 May 2011 19:47:29 +0530 Subject: merge from 5.1 for bug#11764633 --- sql/sql_class.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'sql/sql_class.cc') diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 4af038bb4e0..733d46148c5 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1354,6 +1354,25 @@ bool THD::store_globals() return 0; } +/* + Remove the thread specific info (THD and mem_root pointer) stored during + store_global call for this thread. +*/ +bool THD::restore_globals() +{ + /* + Assert that thread_stack is initialized: it's necessary to be able + to track stack overrun. + */ + DBUG_ASSERT(thread_stack); + + /* Undocking the thread specific data. */ + my_pthread_setspecific_ptr(THR_THD, NULL); + my_pthread_setspecific_ptr(THR_MALLOC, NULL); + + return 0; +} + /* Cleanup after query. -- cgit v1.2.1