Commit d210df50 authored by Michael Widenius's avatar Michael Widenius

Added protection around usage of thd->mysys_var

(May be changed to 0 by scheduler)
parent 847bab8e
......@@ -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
......
......@@ -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
/*
......
......@@ -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.
......
......@@ -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)
{
......
......@@ -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
}
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment