diff options
Diffstat (limited to '')
-rw-r--r-- | sql/sql_manager.cc | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/sql/sql_manager.cc b/sql/sql_manager.cc index 3d3728b9..b3d95c9e 100644 --- a/sql/sql_manager.cc +++ b/sql/sql_manager.cc @@ -26,7 +26,11 @@ #include "sql_manager.h" #include "sql_base.h" // flush_tables -static bool volatile manager_thread_in_use = 0; +/* + Values for manager_thread_in_use: 0 means "not started". 1 means "started + and active". 2 means "stopped". +*/ +static int volatile manager_thread_in_use = 0; static bool abort_manager = false; pthread_t manager_thread; @@ -44,7 +48,7 @@ static struct handler_cb *cb_list; // protected by LOCK_manager bool mysql_manager_submit(void (*action)(void *), void *data) { bool result= FALSE; - DBUG_ASSERT(manager_thread_in_use); + DBUG_ASSERT(manager_thread_in_use == 1); struct handler_cb **cb; mysql_mutex_lock(&LOCK_manager); cb= &cb_list; @@ -76,7 +80,9 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused))) pthread_detach_this_thread(); manager_thread = pthread_self(); mysql_mutex_lock(&LOCK_manager); - while (!abort_manager) + manager_thread_in_use = 1; + mysql_cond_signal(&COND_manager); + while (!abort_manager || cb_list) { /* XXX: This will need to be made more general to handle different * polling needs. */ @@ -116,7 +122,8 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused))) } mysql_mutex_lock(&LOCK_manager); } - manager_thread_in_use = 0; + DBUG_ASSERT(cb_list == NULL); + manager_thread_in_use = 2; mysql_mutex_unlock(&LOCK_manager); mysql_mutex_destroy(&LOCK_manager); mysql_cond_destroy(&COND_manager); @@ -135,12 +142,28 @@ void start_handle_manager() pthread_t hThread; int err; DBUG_EXECUTE_IF("delay_start_handle_manager", my_sleep(1000);); - manager_thread_in_use = 1; mysql_cond_init(key_COND_manager, &COND_manager,NULL); mysql_mutex_init(key_LOCK_manager, &LOCK_manager, NULL); if ((err= mysql_thread_create(key_thread_handle_manager, &hThread, &connection_attrib, handle_manager, 0))) + { sql_print_warning("Can't create handle_manager thread (errno: %M)", err); + DBUG_VOID_RETURN; + } + + mysql_mutex_lock(&LOCK_manager); + /* + Wait for manager thread to have started, otherwise in extreme cases the + server may start up and have initiated shutdown at the time the manager + thread even starts to run. + + Allow both values 1 and 2 for manager_thread_in_use, so that we will not + get stuck here if the manager thread somehow manages to start up and + abort again before we have time to test it here. + */ + while (!manager_thread_in_use) + mysql_cond_wait(&COND_manager, &LOCK_manager); + mysql_mutex_unlock(&LOCK_manager); } DBUG_VOID_RETURN; } |