summaryrefslogtreecommitdiff
path: root/sql/mysqld.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/mysqld.cc')
-rw-r--r--sql/mysqld.cc17
1 files changed, 14 insertions, 3 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index b61e64e627b..1489e3cdc31 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -642,7 +642,7 @@ SHOW_COMP_OPTION have_profiling;
pthread_key(MEM_ROOT**,THR_MALLOC);
pthread_key(THD*, THR_THD);
mysql_mutex_t LOCK_thread_created;
-mysql_mutex_t LOCK_thread_count;
+mysql_mutex_t LOCK_thread_count, LOCK_thd_remove;
mysql_mutex_t
LOCK_status, LOCK_error_log, LOCK_uuid_generator,
LOCK_delayed_insert, LOCK_delayed_status, LOCK_delayed_create,
@@ -1607,6 +1607,7 @@ static void clean_up_mutexes()
mysql_mutex_destroy(&LOCK_prepared_stmt_count);
mysql_mutex_destroy(&LOCK_error_messages);
mysql_cond_destroy(&COND_thread_count);
+ mysql_mutex_destroy(&LOCK_thd_remove);
mysql_cond_destroy(&COND_thread_cache);
mysql_cond_destroy(&COND_flush_thread_cache);
mysql_cond_destroy(&COND_manager);
@@ -2160,6 +2161,8 @@ void dec_connection_count()
void delete_thd(THD *thd)
{
+ mysql_mutex_assert_owner(&LOCK_thread_count);
+ mysql_mutex_assert_owner(&LOCK_thd_remove);
thread_count--;
delete thd;
}
@@ -2173,7 +2176,7 @@ void delete_thd(THD *thd)
thd Thread handler
NOTES
- LOCK_thread_count is locked and left locked
+ LOCK_thread_count, LOCK_thd_remove are locked and left locked
*/
void unlink_thd(THD *thd)
@@ -2183,6 +2186,7 @@ void unlink_thd(THD *thd)
thd_cleanup(thd);
dec_connection_count();
+ mysql_mutex_lock(&LOCK_thd_remove);
mysql_mutex_lock(&LOCK_thread_count);
/*
Used by binlog_reset_master. It would be cleaner to use
@@ -2295,6 +2299,7 @@ bool one_thread_per_connection_end(THD *thd, bool put_in_cache)
{
DBUG_ENTER("one_thread_per_connection_end");
unlink_thd(thd);
+ mysql_mutex_unlock(&LOCK_thd_remove);
if (put_in_cache)
put_in_cache= cache_thread();
mysql_mutex_unlock(&LOCK_thread_count);
@@ -3589,6 +3594,8 @@ static int init_thread_environment()
mysql_mutex_init(key_LOCK_thread_created, &LOCK_thread_created, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_thread_count, &LOCK_thread_count, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_status, &LOCK_status, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(key_LOCK_thd_remove,
+ &LOCK_thd_remove, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_delayed_insert,
&LOCK_delayed_insert, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_delayed_status,
@@ -5080,9 +5087,11 @@ void create_thread_to_handle_connection(THD *thd)
ER_THD(thd, ER_CANT_CREATE_THREAD), error);
net_send_error(thd, ER_CANT_CREATE_THREAD, error_message_buff, NULL);
close_connection(thd);
+ mysql_mutex_lock(&LOCK_thd_remove);
mysql_mutex_lock(&LOCK_thread_count);
delete thd;
mysql_mutex_unlock(&LOCK_thread_count);
+ mysql_mutex_unlock(&LOCK_thd_remove);
return;
/* purecov: end */
}
@@ -7873,6 +7882,7 @@ PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_prep_xids,
key_structure_guard_mutex, key_TABLE_SHARE_LOCK_ha_data,
key_LOCK_error_messages, key_LOG_INFO_lock, key_LOCK_thread_count,
key_PARTITION_LOCK_auto_inc;
+PSI_mutex_key key_LOCK_thd_remove;
PSI_mutex_key key_RELAYLOG_LOCK_index;
PSI_mutex_key key_LOCK_thread_created;
@@ -7928,7 +7938,8 @@ static PSI_mutex_info all_server_mutexes[]=
{ &key_LOG_INFO_lock, "LOG_INFO::lock", 0},
{ &key_LOCK_thread_count, "LOCK_thread_count", PSI_FLAG_GLOBAL},
{ &key_PARTITION_LOCK_auto_inc, "HA_DATA_PARTITION::LOCK_auto_inc", 0},
- { &key_LOCK_thread_created, "LOCK_thread_created", PSI_FLAG_GLOBAL }
+ { &key_LOCK_thread_created, "LOCK_thread_created", PSI_FLAG_GLOBAL },
+ { &key_LOCK_thd_remove, "LOCK_thd_remove", PSI_FLAG_GLOBAL}
};
PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger,