diff options
author | Vladislav Vaintroub <wlad@mariadb.com> | 2016-03-08 10:28:26 +0100 |
---|---|---|
committer | Vladislav Vaintroub <wlad@mariadb.com> | 2016-03-08 10:28:26 +0100 |
commit | 1a3db0e24f8e5be37a9aff2cce4681670f9de044 (patch) | |
tree | 3cdddc9d9857b1a97b200845b416613700855e65 /sql/threadpool_common.cc | |
parent | a8d97fb8186968e193ce0f3c8d1ee416b115e9e0 (diff) | |
download | mariadb-git-1a3db0e24f8e5be37a9aff2cce4681670f9de044.tar.gz |
Fix threadpool after it was broken by MDEV-6150
Diffstat (limited to 'sql/threadpool_common.cc')
-rw-r--r-- | sql/threadpool_common.cc | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/sql/threadpool_common.cc b/sql/threadpool_common.cc index 63622d4a5f0..7cba3f014f4 100644 --- a/sql/threadpool_common.cc +++ b/sql/threadpool_common.cc @@ -94,7 +94,7 @@ struct Worker_thread_context /* Attach/associate the connection with the OS thread, */ -static bool thread_attach(THD* thd) +static void thread_attach(THD* thd) { pthread_setspecific(THR_KEY_mysys,thd->mysys_var); thd->thread_stack=(char*)&thd; @@ -103,13 +103,14 @@ static bool thread_attach(THD* thd) if (PSI_server) PSI_server->set_thread(thd->event_scheduler.m_psi); #endif - return 0; } -int threadpool_add_connection(THD *thd) +THD* threadpool_add_connection(CONNECT *connect, void *scheduler_data) { - int retval=1; + THD *thd= NULL; + int error=1; + Worker_thread_context worker_context; worker_context.save(); @@ -120,13 +121,23 @@ int threadpool_add_connection(THD *thd) pthread_setspecific(THR_KEY_mysys, 0); my_thread_init(); - thd->mysys_var= (st_my_thread_var *)pthread_getspecific(THR_KEY_mysys); - if (!thd->mysys_var) + st_my_thread_var* mysys_var= (st_my_thread_var *)pthread_getspecific(THR_KEY_mysys); + DBUG_EXECUTE_IF("simulate_failed_connection_1", mysys_var= NULL; my_thread_end();); + if (!mysys_var ||!(thd= connect->create_thd())) { /* Out of memory? */ + connect->close_and_delete(); + if (mysys_var) + { + my_thread_end(); + } worker_context.restore(); - return 1; + return NULL; } + delete connect; + add_to_active_threads(thd); + thd->mysys_var= mysys_var; + thd->event_scheduler.data= scheduler_data; /* Create new PSI thread for use with the THD. */ #ifdef HAVE_PSI_INTERFACE @@ -157,14 +168,19 @@ int threadpool_add_connection(THD *thd) */ if (thd_is_connection_alive(thd)) { - retval= 0; + error= 0; thd->net.reading_or_writing= 1; thd->skip_wait_timeout= true; } } } + if (error) + { + threadpool_cleanup_connection(thd); + thd= NULL; + } worker_context.restore(); - return retval; + return thd; } /* |