From b1f0d8ddf53a793ef789d5637c37d8011d5388e4 Mon Sep 17 00:00:00 2001 From: Malavan Sotheeswaran Date: Thu, 27 Jan 2022 10:03:05 -0800 Subject: [PATCH] set thread as offline when waiting for time thread lock --- src/server.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/server.cpp b/src/server.cpp index 9df3764df..eea2032d8 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2956,6 +2956,7 @@ void beforeSleep(struct aeEventLoop *eventLoop) { if (!fSentReplies) handleClientsWithPendingWrites(iel, aof_state); + aeThreadOffline(); // Scope lock_guard { std::unique_lock lock(time_thread_lock); @@ -2972,7 +2973,7 @@ void beforeSleep(struct aeEventLoop *eventLoop) { g_pserver->garbageCollector.endEpoch(epoch); }, true /*fHiPri*/); } - aeThreadOffline(); + /* Determine whether the modules are enabled before sleeping, and use that result both here, and after wakeup to avoid double acquire or release of the GIL */ serverTL->modulesEnabledThisAeLoop = !!moduleCount(); @@ -7205,7 +7206,9 @@ void OnTerminate() void wakeTimeThread() { updateCachedTime(); + aeThreadOffline(); std::unique_lock lock(time_thread_lock); + aeThreadOnline(); if (sleeping_threads >= cserver.cthreads) time_thread_cv.notify_one(); sleeping_threads--; @@ -7220,7 +7223,9 @@ void *timeThreadMain(void*) { aeThreadOnline(); while (true) { { + aeThreadOffline(); std::unique_lock lock(time_thread_lock); + aeThreadOnline(); if (sleeping_threads >= cserver.cthreads) { aeThreadOffline(); time_thread_cv.wait(lock);