mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 12:32:27 +01:00
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.
This commit is contained in:
parent
8553525931
commit
4b3656a44d
4 changed files with 7 additions and 34 deletions
|
@ -689,10 +689,7 @@ static std::atomic<char*> shutdown_user;
|
|||
|
||||
pthread_key(THD*, THR_THD);
|
||||
|
||||
/*
|
||||
LOCK_thread_count protects the following variables:
|
||||
thread_count Number of threads with THD that servers queries.
|
||||
*/
|
||||
/** To be removed */
|
||||
mysql_mutex_t LOCK_thread_count;
|
||||
|
||||
/*
|
||||
|
@ -1794,13 +1791,9 @@ static void close_connections(void)
|
|||
/* All threads has now been aborted */
|
||||
DBUG_PRINT("quit", ("Waiting for threads to die (count=%u)",
|
||||
uint32_t(thread_count)));
|
||||
mysql_mutex_lock(&LOCK_thread_count);
|
||||
|
||||
while (thread_count)
|
||||
{
|
||||
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);
|
||||
my_sleep(1000);
|
||||
|
||||
DBUG_PRINT("quit",("close_connections thread"));
|
||||
DBUG_VOID_RETURN;
|
||||
|
@ -4469,7 +4462,6 @@ static int init_thread_environment()
|
|||
mysql_mutex_init(key_LOCK_global_system_variables,
|
||||
&LOCK_global_system_variables, MY_MUTEX_INIT_FAST);
|
||||
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,
|
||||
&LOCK_system_variables_hash);
|
||||
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)
|
|||
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_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 */
|
||||
proc_info="login";
|
||||
|
@ -1640,8 +1635,6 @@ THD::~THD()
|
|||
DBUG_ENTER("~THD()");
|
||||
/* Make sure threads are not available via server_threads. */
|
||||
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
|
||||
|
|
|
@ -2152,14 +2152,11 @@ struct THD_count
|
|||
*/
|
||||
~THD_count()
|
||||
{
|
||||
uint32_t t= thread_count--;
|
||||
#ifndef DBUG_OFF
|
||||
uint32_t t=
|
||||
#endif
|
||||
thread_count--;
|
||||
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)
|
|||
thd->profiling.set_query_source(thd->query(), length);
|
||||
#endif
|
||||
|
||||
/*
|
||||
We don't need to obtain LOCK_thread_count here because in bootstrap
|
||||
mode we have only one thread.
|
||||
*/
|
||||
thd->set_time();
|
||||
Parser_state parser_state;
|
||||
if (parser_state.init(thd, thd->query(), length))
|
||||
|
@ -8994,9 +8990,6 @@ THD *find_thread_by_id(longlong id, bool query_id)
|
|||
@param id Thread id or query id
|
||||
@param kill_signal Should it kill the query or the connection
|
||||
@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
|
||||
|
@ -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
|
||||
|
||||
@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
|
||||
are killed.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue