diff options
-rw-r--r-- | sql/mysqld.cc | 2 | ||||
-rw-r--r-- | sql/scheduler.cc | 4 | ||||
-rw-r--r-- | sql/sql_class.cc | 13 | ||||
-rw-r--r-- | sql/sql_class.h | 1 | ||||
-rw-r--r-- | sql/sql_insert.cc | 2 | ||||
-rw-r--r-- | sql/sql_show.cc | 2 |
6 files changed, 21 insertions, 3 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 53b95527a91..bb982cdb7af 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -957,6 +957,7 @@ static void close_connections(void) tmp->killed= THD::KILL_CONNECTION; thread_scheduler.post_kill_notification(tmp); + pthread_mutex_lock(&tmp->LOCK_thd_data); if (tmp->mysys_var) { tmp->mysys_var->abort=1; @@ -979,6 +980,7 @@ static void close_connections(void) } pthread_mutex_unlock(&tmp->mysys_var->mutex); } + pthread_mutex_unlock(&tmp->LOCK_thd_data); } (void) pthread_mutex_unlock(&LOCK_thread_count); // For unlink from list diff --git a/sql/scheduler.cc b/sql/scheduler.cc index e0a7837de8e..5b8f834aecc 100644 --- a/sql/scheduler.cc +++ b/sql/scheduler.cc @@ -235,9 +235,7 @@ void thd_scheduler::thread_detach() if (thread_attached) { THD* thd = (THD*)list.data; - pthread_mutex_lock(&thd->LOCK_thd_data); - thd->mysys_var= NULL; - pthread_mutex_unlock(&thd->LOCK_thd_data); + thd->reset_globals(); thread_attached= FALSE; #ifndef DBUG_OFF /* diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 0805eda59e4..68d8ba4a189 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1166,6 +1166,19 @@ bool THD::store_globals() } +/** + Untie THD from current thread + + Used when using --thread-handling=pool-of-threads +*/ + +void THD::reset_globals() +{ + pthread_mutex_lock(&LOCK_thd_data); + mysys_var= 0; + pthread_mutex_unlock(&LOCK_thd_data); +} + /* Cleanup after query. diff --git a/sql/sql_class.h b/sql/sql_class.h index 60ab952a3ab..3ea5368a9c4 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1906,6 +1906,7 @@ public: void cleanup(void); void cleanup_after_query(); bool store_globals(); + void reset_globals(); #ifdef SIGNAL_WITH_VIO_CLOSE inline void set_active_vio(Vio* vio) { diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 0cd67a16a25..3e32209f956 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2279,6 +2279,7 @@ void kill_delayed_threads(void) while ((di= it++)) { di->thd.killed= THD::KILL_CONNECTION; + pthread_mutex_lock(&di->thd.LOCK_thd_data); if (di->thd.mysys_var) { pthread_mutex_lock(&di->thd.mysys_var->mutex); @@ -2297,6 +2298,7 @@ void kill_delayed_threads(void) } pthread_mutex_unlock(&di->thd.mysys_var->mutex); } + pthread_mutex_unlock(&di->thd.LOCK_thd_data); } VOID(pthread_mutex_unlock(&LOCK_delayed_insert)); // For unlink from list } diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 0601aa976b8..918227122ed 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1747,6 +1747,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) if ((thd_info->db=tmp->db)) // Safe test thd_info->db=thd->strdup(thd_info->db); thd_info->command=(int) tmp->command; + pthread_mutex_lock(&tmp->LOCK_thd_data); if ((mysys_var= tmp->mysys_var)) pthread_mutex_lock(&mysys_var->mutex); thd_info->proc_info= (char*) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0); @@ -1766,6 +1767,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) #endif if (mysys_var) pthread_mutex_unlock(&mysys_var->mutex); + pthread_mutex_unlock(&tmp->LOCK_thd_data); thd_info->start_time= tmp->start_time; thd_info->query=0; |