Commit 688e87a9 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Fix embedded/windows tests- move COND_manager and LOCK_manager to...

Fix embedded/windows tests- move COND_manager and LOCK_manager to sql_manager.cc, to prevent race condition  that results into accessing already destroyed critical section
parent 4252d667
...@@ -2091,7 +2091,7 @@ extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open, LOCK_lock_db, ...@@ -2091,7 +2091,7 @@ extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open, LOCK_lock_db,
LOCK_mapped_file,LOCK_user_locks, LOCK_status, LOCK_mapped_file,LOCK_user_locks, LOCK_status,
LOCK_error_log, LOCK_delayed_insert, LOCK_short_uuid_generator, LOCK_error_log, LOCK_delayed_insert, LOCK_short_uuid_generator,
LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone, LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone,
LOCK_slave_list, LOCK_active_mi, LOCK_manager, LOCK_global_read_lock, LOCK_slave_list, LOCK_active_mi, LOCK_global_read_lock,
LOCK_global_system_variables, LOCK_user_conn, LOCK_global_system_variables, LOCK_user_conn,
LOCK_prepared_stmt_count, LOCK_prepared_stmt_count,
LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count; LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count;
...@@ -2109,7 +2109,7 @@ extern pthread_mutex_t LOCK_stats; ...@@ -2109,7 +2109,7 @@ extern pthread_mutex_t LOCK_stats;
extern int mysqld_server_started; extern int mysqld_server_started;
extern rw_lock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave; extern rw_lock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave;
extern rw_lock_t LOCK_system_variables_hash; extern rw_lock_t LOCK_system_variables_hash;
extern pthread_cond_t COND_refresh, COND_thread_count, COND_manager; extern pthread_cond_t COND_refresh, COND_thread_count;
extern pthread_cond_t COND_global_read_lock; extern pthread_cond_t COND_global_read_lock;
extern pthread_attr_t connection_attrib; extern pthread_attr_t connection_attrib;
extern I_List<THD> threads; extern I_List<THD> threads;
......
...@@ -1516,7 +1516,6 @@ static void clean_up_mutexes() ...@@ -1516,7 +1516,6 @@ static void clean_up_mutexes()
(void) pthread_mutex_destroy(&LOCK_delayed_insert); (void) pthread_mutex_destroy(&LOCK_delayed_insert);
(void) pthread_mutex_destroy(&LOCK_delayed_status); (void) pthread_mutex_destroy(&LOCK_delayed_status);
(void) pthread_mutex_destroy(&LOCK_delayed_create); (void) pthread_mutex_destroy(&LOCK_delayed_create);
(void) pthread_mutex_destroy(&LOCK_manager);
(void) pthread_mutex_destroy(&LOCK_crypt); (void) pthread_mutex_destroy(&LOCK_crypt);
(void) pthread_mutex_destroy(&LOCK_bytes_sent); (void) pthread_mutex_destroy(&LOCK_bytes_sent);
(void) pthread_mutex_destroy(&LOCK_bytes_received); (void) pthread_mutex_destroy(&LOCK_bytes_received);
...@@ -1557,7 +1556,6 @@ static void clean_up_mutexes() ...@@ -1557,7 +1556,6 @@ static void clean_up_mutexes()
(void) pthread_cond_destroy(&COND_global_read_lock); (void) pthread_cond_destroy(&COND_global_read_lock);
(void) pthread_cond_destroy(&COND_thread_cache); (void) pthread_cond_destroy(&COND_thread_cache);
(void) pthread_cond_destroy(&COND_flush_thread_cache); (void) pthread_cond_destroy(&COND_flush_thread_cache);
(void) pthread_cond_destroy(&COND_manager);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -3817,7 +3815,6 @@ static int init_thread_environment() ...@@ -3817,7 +3815,6 @@ static int init_thread_environment()
(void) pthread_mutex_init(&LOCK_delayed_insert,MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_delayed_insert,MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_delayed_status,MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_delayed_status,MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_delayed_create,MY_MUTEX_INIT_SLOW); (void) pthread_mutex_init(&LOCK_delayed_create,MY_MUTEX_INIT_SLOW);
(void) pthread_mutex_init(&LOCK_manager,MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_crypt,MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_crypt,MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_bytes_sent,MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_bytes_sent,MY_MUTEX_INIT_FAST);
(void) pthread_mutex_init(&LOCK_bytes_received,MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_bytes_received,MY_MUTEX_INIT_FAST);
...@@ -3857,7 +3854,6 @@ static int init_thread_environment() ...@@ -3857,7 +3854,6 @@ static int init_thread_environment()
(void) pthread_cond_init(&COND_global_read_lock,NULL); (void) pthread_cond_init(&COND_global_read_lock,NULL);
(void) pthread_cond_init(&COND_thread_cache,NULL); (void) pthread_cond_init(&COND_thread_cache,NULL);
(void) pthread_cond_init(&COND_flush_thread_cache,NULL); (void) pthread_cond_init(&COND_flush_thread_cache,NULL);
(void) pthread_cond_init(&COND_manager,NULL);
#ifdef HAVE_REPLICATION #ifdef HAVE_REPLICATION
(void) pthread_mutex_init(&LOCK_rpl_status, MY_MUTEX_INIT_FAST); (void) pthread_mutex_init(&LOCK_rpl_status, MY_MUTEX_INIT_FAST);
(void) pthread_cond_init(&COND_rpl_status, NULL); (void) pthread_cond_init(&COND_rpl_status, NULL);
......
...@@ -44,6 +44,7 @@ static struct handler_cb * volatile cb_list; ...@@ -44,6 +44,7 @@ static struct handler_cb * volatile cb_list;
bool mysql_manager_submit(void (*action)()) bool mysql_manager_submit(void (*action)())
{ {
bool result= FALSE; bool result= FALSE;
DBUG_ASSERT(manager_thread_in_use);
struct handler_cb * volatile *cb; struct handler_cb * volatile *cb;
pthread_mutex_lock(&LOCK_manager); pthread_mutex_lock(&LOCK_manager);
cb= &cb_list; cb= &cb_list;
...@@ -75,8 +76,9 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused))) ...@@ -75,8 +76,9 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused)))
pthread_detach_this_thread(); pthread_detach_this_thread();
manager_thread = pthread_self(); manager_thread = pthread_self();
(void) pthread_cond_init(&COND_manager,NULL);
(void) pthread_mutex_init(&LOCK_manager,NULL);
manager_thread_in_use = 1; manager_thread_in_use = 1;
for (;;) for (;;)
{ {
pthread_mutex_lock(&LOCK_manager); pthread_mutex_lock(&LOCK_manager);
...@@ -123,6 +125,8 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused))) ...@@ -123,6 +125,8 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused)))
} }
} }
manager_thread_in_use = 0; manager_thread_in_use = 0;
(void) pthread_mutex_destroy(&LOCK_manager);
(void) pthread_cond_destroy(&COND_manager);
DBUG_LEAVE; // Can't use DBUG_RETURN after my_thread_end DBUG_LEAVE; // Can't use DBUG_RETURN after my_thread_end
my_thread_end(); my_thread_end();
return (NULL); return (NULL);
...@@ -149,14 +153,14 @@ void stop_handle_manager() ...@@ -149,14 +153,14 @@ void stop_handle_manager()
{ {
DBUG_ENTER("stop_handle_manager"); DBUG_ENTER("stop_handle_manager");
abort_manager = true; abort_manager = true;
pthread_mutex_lock(&LOCK_manager);
if (manager_thread_in_use) if (manager_thread_in_use)
{ {
pthread_mutex_lock(&LOCK_manager);
DBUG_PRINT("quit", ("initiate shutdown of handle manager thread: 0x%lx", DBUG_PRINT("quit", ("initiate shutdown of handle manager thread: 0x%lx",
(ulong)manager_thread)); (ulong)manager_thread));
pthread_cond_signal(&COND_manager); pthread_cond_signal(&COND_manager);
}
pthread_mutex_unlock(&LOCK_manager); pthread_mutex_unlock(&LOCK_manager);
}
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
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