summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Vojtovich <svoj@mariadb.org>2019-01-29 01:13:47 +0400
committerSergey Vojtovich <svoj@mariadb.org>2019-01-29 11:56:35 +0400
commit4b3656a44d67f6f96fc71fef522207db0dbb3369 (patch)
treef61fe3a811d3acd464b75e27d52cd827cd3dd417
parent8553525931fa34fb89f3bb12ffd07c99f4d436f5 (diff)
downloadmariadb-git-4b3656a44d67f6f96fc71fef522207db0dbb3369.tar.gz
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.
-rw-r--r--sql/mysqld.cc14
-rw-r--r--sql/sql_class.cc7
-rw-r--r--sql/sql_class.h11
-rw-r--r--sql/sql_parse.cc9
4 files changed, 7 insertions, 34 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index bfac56b6549..3d44d6078df 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -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,
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 9ddf89b14db..78bfbd4dbd2 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -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
diff --git a/sql/sql_class.h b/sql/sql_class.h
index c20dbe7d409..04044b0d005 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -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);
- }
}
};
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index f543d3b8dd4..7360ecb62da 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -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.
*/