[Maria-developers] bzr commit into MariaDB 5.1, with Maria 1.5:maria branch (monty:2769)
#At lp:maria based on revid:monty@askmonty.org-20091126155705-5g7fmkbcpdu6ad6j 2769 Michael Widenius 2009-11-26 Added protection around usage of thd->mysys_var (May be changed to 0 by scheduler) modified: sql/mysqld.cc sql/scheduler.cc sql/sql_class.cc sql/sql_class.h sql/sql_insert.cc sql/sql_show.cc === modified file 'sql/mysqld.cc' --- a/sql/mysqld.cc 2009-10-31 19:22:50 +0000 +++ b/sql/mysqld.cc 2009-11-26 20:19:33 +0000 @@ -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 === modified file 'sql/scheduler.cc' --- a/sql/scheduler.cc 2009-09-07 20:50:10 +0000 +++ b/sql/scheduler.cc 2009-11-26 20:19:33 +0000 @@ -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 /* === modified file 'sql/sql_class.cc' --- a/sql/sql_class.cc 2009-09-15 10:46:35 +0000 +++ b/sql/sql_class.cc 2009-11-26 20:19:33 +0000 @@ -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. === modified file 'sql/sql_class.h' --- a/sql/sql_class.h 2009-09-15 10:46:35 +0000 +++ b/sql/sql_class.h 2009-11-26 20:19:33 +0000 @@ -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) { === modified file 'sql/sql_insert.cc' --- a/sql/sql_insert.cc 2009-11-07 10:34:19 +0000 +++ b/sql/sql_insert.cc 2009-11-26 20:19:33 +0000 @@ -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 } === modified file 'sql/sql_show.cc' --- a/sql/sql_show.cc 2009-11-02 09:30:21 +0000 +++ b/sql/sql_show.cc 2009-11-26 20:19:33 +0000 @@ -1747,6 +1747,7 @@ void mysqld_list_processes(THD *thd,cons 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,cons #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;
participants (1)
-
Michael Widenius