Commit 8b4fcc43 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub Committed by Sergey Vojtovich

Use rwlock rather than mutex for protecting THD_list

modifications (insert/erase) are protected by write lock
iteration over list is protected by read lock.

This way, threads that iterate over the list (as in SHOW PROCESSLIST,
SHOW GLOBAL STATUS) do not block each other.
parent 9824ec81
...@@ -890,7 +890,7 @@ PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_xid_list, ...@@ -890,7 +890,7 @@ PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_xid_list,
key_structure_guard_mutex, key_TABLE_SHARE_LOCK_ha_data, key_structure_guard_mutex, key_TABLE_SHARE_LOCK_ha_data,
key_LOCK_error_messages, key_LOCK_error_messages,
key_LOCK_start_thread, key_LOCK_start_thread,
key_LOCK_thread_count, key_Thread_map_mutex, key_LOCK_thread_cache, key_LOCK_thread_count, key_LOCK_thread_cache,
key_PARTITION_LOCK_auto_inc; key_PARTITION_LOCK_auto_inc;
PSI_mutex_key key_RELAYLOG_LOCK_index; PSI_mutex_key key_RELAYLOG_LOCK_index;
PSI_mutex_key key_LOCK_relaylog_end_pos; PSI_mutex_key key_LOCK_relaylog_end_pos;
...@@ -984,7 +984,6 @@ static PSI_mutex_info all_server_mutexes[]= ...@@ -984,7 +984,6 @@ static PSI_mutex_info all_server_mutexes[]=
{ &key_LOCK_commit_ordered, "LOCK_commit_ordered", PSI_FLAG_GLOBAL}, { &key_LOCK_commit_ordered, "LOCK_commit_ordered", PSI_FLAG_GLOBAL},
{ &key_LOCK_slave_background, "LOCK_slave_background", PSI_FLAG_GLOBAL}, { &key_LOCK_slave_background, "LOCK_slave_background", PSI_FLAG_GLOBAL},
{ &key_LOCK_thread_count, "LOCK_thread_count", PSI_FLAG_GLOBAL}, { &key_LOCK_thread_count, "LOCK_thread_count", PSI_FLAG_GLOBAL},
{ &key_Thread_map_mutex, "Thread_map::mutex", PSI_FLAG_GLOBAL },
{ &key_LOCK_thread_cache, "LOCK_thread_cache", PSI_FLAG_GLOBAL}, { &key_LOCK_thread_cache, "LOCK_thread_cache", PSI_FLAG_GLOBAL},
{ &key_PARTITION_LOCK_auto_inc, "HA_DATA_PARTITION::LOCK_auto_inc", 0}, { &key_PARTITION_LOCK_auto_inc, "HA_DATA_PARTITION::LOCK_auto_inc", 0},
{ &key_LOCK_slave_state, "LOCK_slave_state", 0}, { &key_LOCK_slave_state, "LOCK_slave_state", 0},
...@@ -1002,7 +1001,8 @@ PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger, ...@@ -1002,7 +1001,8 @@ PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger,
key_rwlock_LOCK_system_variables_hash, key_rwlock_query_cache_query_lock, key_rwlock_LOCK_system_variables_hash, key_rwlock_query_cache_query_lock,
key_LOCK_SEQUENCE, key_LOCK_SEQUENCE,
key_rwlock_LOCK_vers_stats, key_rwlock_LOCK_stat_serial, key_rwlock_LOCK_vers_stats, key_rwlock_LOCK_stat_serial,
key_rwlock_LOCK_ssl_refresh; key_rwlock_LOCK_ssl_refresh,
key_rwlock_THD_list;
static PSI_rwlock_info all_server_rwlocks[]= static PSI_rwlock_info all_server_rwlocks[]=
{ {
...@@ -1018,7 +1018,8 @@ static PSI_rwlock_info all_server_rwlocks[]= ...@@ -1018,7 +1018,8 @@ static PSI_rwlock_info all_server_rwlocks[]=
{ &key_rwlock_query_cache_query_lock, "Query_cache_query::lock", 0}, { &key_rwlock_query_cache_query_lock, "Query_cache_query::lock", 0},
{ &key_rwlock_LOCK_vers_stats, "Vers_field_stats::lock", 0}, { &key_rwlock_LOCK_vers_stats, "Vers_field_stats::lock", 0},
{ &key_rwlock_LOCK_stat_serial, "TABLE_SHARE::LOCK_stat_serial", 0}, { &key_rwlock_LOCK_stat_serial, "TABLE_SHARE::LOCK_stat_serial", 0},
{ &key_rwlock_LOCK_ssl_refresh, "LOCK_ssl_refresh", PSI_FLAG_GLOBAL } { &key_rwlock_LOCK_ssl_refresh, "LOCK_ssl_refresh", PSI_FLAG_GLOBAL },
{ &key_rwlock_THD_list, "THD_list::lock", PSI_FLAG_GLOBAL }
}; };
#ifdef HAVE_MMAP #ifdef HAVE_MMAP
......
...@@ -344,7 +344,7 @@ extern PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_xid_list, ...@@ -344,7 +344,7 @@ extern PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_xid_list,
key_rpl_group_info_sleep_lock, key_rpl_group_info_sleep_lock,
key_structure_guard_mutex, key_TABLE_SHARE_LOCK_ha_data, key_structure_guard_mutex, key_TABLE_SHARE_LOCK_ha_data,
key_LOCK_start_thread, key_LOCK_start_thread,
key_LOCK_error_messages, key_LOCK_thread_count, key_Thread_map_mutex, key_LOCK_error_messages,
key_PARTITION_LOCK_auto_inc; key_PARTITION_LOCK_auto_inc;
extern PSI_mutex_key key_RELAYLOG_LOCK_index; extern PSI_mutex_key key_RELAYLOG_LOCK_index;
extern PSI_mutex_key key_LOCK_relaylog_end_pos; extern PSI_mutex_key key_LOCK_relaylog_end_pos;
...@@ -361,7 +361,8 @@ extern PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger, ...@@ -361,7 +361,8 @@ extern PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger,
key_rwlock_LOCK_sys_init_connect, key_rwlock_LOCK_sys_init_slave, key_rwlock_LOCK_sys_init_connect, key_rwlock_LOCK_sys_init_slave,
key_rwlock_LOCK_system_variables_hash, key_rwlock_query_cache_query_lock, key_rwlock_LOCK_system_variables_hash, key_rwlock_query_cache_query_lock,
key_LOCK_SEQUENCE, key_LOCK_SEQUENCE,
key_rwlock_LOCK_vers_stats, key_rwlock_LOCK_stat_serial; key_rwlock_LOCK_vers_stats, key_rwlock_LOCK_stat_serial,
key_rwlock_THD_list;
#ifdef HAVE_MMAP #ifdef HAVE_MMAP
extern PSI_cond_key key_PAGE_cond, key_COND_active, key_COND_pool; extern PSI_cond_key key_PAGE_cond, key_COND_active, key_COND_pool;
......
...@@ -6939,7 +6939,7 @@ class ScopedStatementReplication ...@@ -6939,7 +6939,7 @@ class ScopedStatementReplication
class THD_list class THD_list
{ {
I_List<THD> threads; I_List<THD> threads;
mutable mysql_mutex_t mutex; mutable mysql_rwlock_t lock;
public: public:
/** /**
...@@ -6951,13 +6951,13 @@ class THD_list ...@@ -6951,13 +6951,13 @@ class THD_list
*/ */
void init() void init()
{ {
mysql_mutex_init(key_Thread_map_mutex, &mutex, MY_MUTEX_INIT_FAST); mysql_rwlock_init(key_rwlock_THD_list, &lock);
} }
/** Destructor replacement. */ /** Destructor replacement. */
void destroy() void destroy()
{ {
mysql_mutex_destroy(&mutex); mysql_rwlock_destroy(&lock);
} }
/** /**
...@@ -6969,9 +6969,9 @@ class THD_list ...@@ -6969,9 +6969,9 @@ class THD_list
*/ */
void insert(THD *thd) void insert(THD *thd)
{ {
mysql_mutex_lock(&mutex); mysql_rwlock_wrlock(&lock);
threads.append(thd); threads.append(thd);
mysql_mutex_unlock(&mutex); mysql_rwlock_unlock(&lock);
} }
/** /**
...@@ -6984,9 +6984,9 @@ class THD_list ...@@ -6984,9 +6984,9 @@ class THD_list
void erase(THD *thd) void erase(THD *thd)
{ {
thd->assert_linked(); thd->assert_linked();
mysql_mutex_lock(&mutex); mysql_rwlock_wrlock(&lock);
thd->unlink(); thd->unlink();
mysql_mutex_unlock(&mutex); mysql_rwlock_unlock(&lock);
} }
/** /**
...@@ -7002,12 +7002,12 @@ class THD_list ...@@ -7002,12 +7002,12 @@ class THD_list
template <typename T> int iterate(my_bool (*action)(THD *thd, T *arg), T *arg= 0) template <typename T> int iterate(my_bool (*action)(THD *thd, T *arg), T *arg= 0)
{ {
int res= 0; int res= 0;
mysql_mutex_lock(&mutex); mysql_rwlock_rdlock(&lock);
I_List_iterator<THD> it(threads); I_List_iterator<THD> it(threads);
while (auto tmp= it++) while (auto tmp= it++)
if ((res= action(tmp, arg))) if ((res= action(tmp, arg)))
break; break;
mysql_mutex_unlock(&mutex); mysql_rwlock_unlock(&lock);
return res; return res;
} }
}; };
......
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