Commit 4b3656a4 authored by Sergey Vojtovich's avatar Sergey Vojtovich

Avoid taking LOCK_thread_count for thread_count protection

Replaced wait on COND_thread_count with busy waiting with 1 millisecond
sleep.

Aim is to reduce usage of LOCK_thread_count and COND_thread_count.
parent 85535259
...@@ -689,10 +689,7 @@ static std::atomic<char*> shutdown_user; ...@@ -689,10 +689,7 @@ static std::atomic<char*> shutdown_user;
pthread_key(THD*, THR_THD); pthread_key(THD*, THR_THD);
/* /** To be removed */
LOCK_thread_count protects the following variables:
thread_count Number of threads with THD that servers queries.
*/
mysql_mutex_t LOCK_thread_count; mysql_mutex_t LOCK_thread_count;
/* /*
...@@ -1794,13 +1791,9 @@ static void close_connections(void) ...@@ -1794,13 +1791,9 @@ static void close_connections(void)
/* All threads has now been aborted */ /* All threads has now been aborted */
DBUG_PRINT("quit", ("Waiting for threads to die (count=%u)", DBUG_PRINT("quit", ("Waiting for threads to die (count=%u)",
uint32_t(thread_count))); uint32_t(thread_count)));
mysql_mutex_lock(&LOCK_thread_count);
while (thread_count) while (thread_count)
{ my_sleep(1000);
mysql_cond_wait(&COND_thread_count, &LOCK_thread_count);
DBUG_PRINT("quit",("One thread died (count=%u)", uint32_t(thread_count)));
}
mysql_mutex_unlock(&LOCK_thread_count);
DBUG_PRINT("quit",("close_connections thread")); DBUG_PRINT("quit",("close_connections thread"));
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
...@@ -4469,7 +4462,6 @@ static int init_thread_environment() ...@@ -4469,7 +4462,6 @@ static int init_thread_environment()
mysql_mutex_init(key_LOCK_global_system_variables, mysql_mutex_init(key_LOCK_global_system_variables,
&LOCK_global_system_variables, MY_MUTEX_INIT_FAST); &LOCK_global_system_variables, MY_MUTEX_INIT_FAST);
mysql_mutex_record_order(&LOCK_active_mi, &LOCK_global_system_variables); mysql_mutex_record_order(&LOCK_active_mi, &LOCK_global_system_variables);
mysql_mutex_record_order(&LOCK_status, &LOCK_thread_count);
mysql_prlock_init(key_rwlock_LOCK_system_variables_hash, mysql_prlock_init(key_rwlock_LOCK_system_variables_hash,
&LOCK_system_variables_hash); &LOCK_system_variables_hash);
mysql_mutex_init(key_LOCK_prepared_stmt_count, mysql_mutex_init(key_LOCK_prepared_stmt_count,
......
...@@ -786,11 +786,6 @@ THD::THD(my_thread_id id, bool is_wsrep_applier, bool skip_global_sys_var_lock) ...@@ -786,11 +786,6 @@ THD::THD(my_thread_id id, bool is_wsrep_applier, bool skip_global_sys_var_lock)
mysql_mutex_init(key_LOCK_wakeup_ready, &LOCK_wakeup_ready, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_wakeup_ready, &LOCK_wakeup_ready, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_thd_kill, &LOCK_thd_kill, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_LOCK_thd_kill, &LOCK_thd_kill, MY_MUTEX_INIT_FAST);
mysql_cond_init(key_COND_wakeup_ready, &COND_wakeup_ready, 0); mysql_cond_init(key_COND_wakeup_ready, &COND_wakeup_ready, 0);
/*
LOCK_thread_count goes before LOCK_thd_data - the former is called around
'delete thd', the latter - in THD::~THD
*/
mysql_mutex_record_order(&LOCK_thread_count, &LOCK_thd_data);
/* Variables with default values */ /* Variables with default values */
proc_info="login"; proc_info="login";
...@@ -1640,8 +1635,6 @@ THD::~THD() ...@@ -1640,8 +1635,6 @@ THD::~THD()
DBUG_ENTER("~THD()"); DBUG_ENTER("~THD()");
/* Make sure threads are not available via server_threads. */ /* Make sure threads are not available via server_threads. */
assert_not_linked(); assert_not_linked();
/* This takes a long time so we should not do this under LOCK_thread_count */
mysql_mutex_assert_not_owner(&LOCK_thread_count);
/* /*
In error cases, thd may not be current thd. We have to fix this so In error cases, thd may not be current thd. We have to fix this so
......
...@@ -2152,14 +2152,11 @@ struct THD_count ...@@ -2152,14 +2152,11 @@ struct THD_count
*/ */
~THD_count() ~THD_count()
{ {
uint32_t t= thread_count--; #ifndef DBUG_OFF
uint32_t t=
#endif
thread_count--;
DBUG_ASSERT(t > 0); DBUG_ASSERT(t > 0);
if (t == 1)
{
mysql_mutex_lock(&LOCK_thread_count);
mysql_cond_broadcast(&COND_thread_count);
mysql_mutex_unlock(&LOCK_thread_count);
}
} }
}; };
......
...@@ -1077,10 +1077,6 @@ void bootstrap(MYSQL_FILE *file) ...@@ -1077,10 +1077,6 @@ void bootstrap(MYSQL_FILE *file)
thd->profiling.set_query_source(thd->query(), length); thd->profiling.set_query_source(thd->query(), length);
#endif #endif
/*
We don't need to obtain LOCK_thread_count here because in bootstrap
mode we have only one thread.
*/
thd->set_time(); thd->set_time();
Parser_state parser_state; Parser_state parser_state;
if (parser_state.init(thd, thd->query(), length)) if (parser_state.init(thd, thd->query(), length))
...@@ -8994,9 +8990,6 @@ THD *find_thread_by_id(longlong id, bool query_id) ...@@ -8994,9 +8990,6 @@ THD *find_thread_by_id(longlong id, bool query_id)
@param id Thread id or query id @param id Thread id or query id
@param kill_signal Should it kill the query or the connection @param kill_signal Should it kill the query or the connection
@param type Type of id: thread id or query id @param type Type of id: thread id or query id
@note
This is written such that we have a short lock on LOCK_thread_count
*/ */
uint uint
...@@ -9061,8 +9054,6 @@ kill_one_thread(THD *thd, longlong id, killed_state kill_signal, killed_type typ ...@@ -9061,8 +9054,6 @@ kill_one_thread(THD *thd, longlong id, killed_state kill_signal, killed_type typ
@param only_kill_query Should it kill the query or the connection @param only_kill_query Should it kill the query or the connection
@note @note
This is written such that we have a short lock on LOCK_thread_count
If we can't kill all threads because of security issues, no threads If we can't kill all threads because of security issues, no threads
are killed. are killed.
*/ */
......
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