summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2020-02-06 10:29:46 +0100
committerGitHub <noreply@github.com>2020-02-06 10:29:46 +0100
commit7cf53252eedd0251aeb66be8513a3a7f1fd4b30d (patch)
treece25b2cc0adee8a87833b512200ba346d90c812e /src
parent44266d6d9288c3d48e6fb8c198c34561329c1cef (diff)
parent86e302f5f302da89790f03000e9f76d322b5f971 (diff)
downloadredis-7cf53252eedd0251aeb66be8513a3a7f1fd4b30d.tar.gz
Merge pull request #6849 from oranagra/free_client_mutex
freeClientAsync don't lock mutex if there's just one thread
Diffstat (limited to 'src')
-rw-r--r--src/networking.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/networking.c b/src/networking.c
index 496b0f3dc..2b0f7464a 100644
--- a/src/networking.c
+++ b/src/networking.c
@@ -1163,9 +1163,14 @@ void freeClientAsync(client *c) {
* may access the list while Redis uses I/O threads. All the other accesses
* are in the context of the main thread while the other threads are
* idle. */
- static pthread_mutex_t async_free_queue_mutex = PTHREAD_MUTEX_INITIALIZER;
if (c->flags & CLIENT_CLOSE_ASAP || c->flags & CLIENT_LUA) return;
c->flags |= CLIENT_CLOSE_ASAP;
+ if (server.io_threads_num == 1) {
+ /* no need to bother with locking if there's just one thread (the main thread) */
+ listAddNodeTail(server.clients_to_close,c);
+ return;
+ }
+ static pthread_mutex_t async_free_queue_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_lock(&async_free_queue_mutex);
listAddNodeTail(server.clients_to_close,c);
pthread_mutex_unlock(&async_free_queue_mutex);