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);