Commit e38a05e2 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Fix create_background_thd()

Allow the caller to have current_thd. Also do not store
PSI_CALL_get_thread() in the new THD, it is a thread local storage variable
that can become invalid any time, we do not control the lifetime of the
caller's thread.
parent 10f08aff
...@@ -4894,11 +4894,13 @@ void destroy_thd(MYSQL_THD thd) ...@@ -4894,11 +4894,13 @@ void destroy_thd(MYSQL_THD thd)
extern "C" pthread_key(struct st_my_thread_var *, THR_KEY_mysys); extern "C" pthread_key(struct st_my_thread_var *, THR_KEY_mysys);
MYSQL_THD create_background_thd() MYSQL_THD create_background_thd()
{ {
DBUG_ASSERT(!current_thd); auto save_thd = current_thd;
set_current_thd(nullptr);
auto save_mysysvar= pthread_getspecific(THR_KEY_mysys); auto save_mysysvar= pthread_getspecific(THR_KEY_mysys);
/* /*
Allocate new mysys_var specifically this THD, Allocate new mysys_var specifically new THD,
so that e.g safemalloc, DBUG etc are happy. so that e.g safemalloc, DBUG etc are happy.
*/ */
pthread_setspecific(THR_KEY_mysys, 0); pthread_setspecific(THR_KEY_mysys, 0);
...@@ -4906,7 +4908,8 @@ MYSQL_THD create_background_thd() ...@@ -4906,7 +4908,8 @@ MYSQL_THD create_background_thd()
auto thd_mysysvar= pthread_getspecific(THR_KEY_mysys); auto thd_mysysvar= pthread_getspecific(THR_KEY_mysys);
auto thd= new THD(0); auto thd= new THD(0);
pthread_setspecific(THR_KEY_mysys, save_mysysvar); pthread_setspecific(THR_KEY_mysys, save_mysysvar);
thd->set_psi(PSI_CALL_get_thread()); thd->set_psi(nullptr);
set_current_thd(save_thd);
/* /*
Workaround the adverse effect of incrementing thread_count Workaround the adverse effect of incrementing thread_count
......
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