set thread as offline when waiting for time thread lock

This commit is contained in:
Malavan Sotheeswaran 2022-01-27 10:03:05 -08:00 committed by Vivek Saini
parent 395eb1fd3a
commit b1f0d8ddf5

View File

@ -2956,6 +2956,7 @@ void beforeSleep(struct aeEventLoop *eventLoop) {
if (!fSentReplies) if (!fSentReplies)
handleClientsWithPendingWrites(iel, aof_state); handleClientsWithPendingWrites(iel, aof_state);
aeThreadOffline();
// Scope lock_guard // Scope lock_guard
{ {
std::unique_lock<fastlock> lock(time_thread_lock); std::unique_lock<fastlock> lock(time_thread_lock);
@ -2972,7 +2973,7 @@ void beforeSleep(struct aeEventLoop *eventLoop) {
g_pserver->garbageCollector.endEpoch(epoch); g_pserver->garbageCollector.endEpoch(epoch);
}, true /*fHiPri*/); }, true /*fHiPri*/);
} }
aeThreadOffline();
/* Determine whether the modules are enabled before sleeping, and use that result /* 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 */ both here, and after wakeup to avoid double acquire or release of the GIL */
serverTL->modulesEnabledThisAeLoop = !!moduleCount(); serverTL->modulesEnabledThisAeLoop = !!moduleCount();
@ -7205,7 +7206,9 @@ void OnTerminate()
void wakeTimeThread() { void wakeTimeThread() {
updateCachedTime(); updateCachedTime();
aeThreadOffline();
std::unique_lock<fastlock> lock(time_thread_lock); std::unique_lock<fastlock> lock(time_thread_lock);
aeThreadOnline();
if (sleeping_threads >= cserver.cthreads) if (sleeping_threads >= cserver.cthreads)
time_thread_cv.notify_one(); time_thread_cv.notify_one();
sleeping_threads--; sleeping_threads--;
@ -7220,7 +7223,9 @@ void *timeThreadMain(void*) {
aeThreadOnline(); aeThreadOnline();
while (true) { while (true) {
{ {
aeThreadOffline();
std::unique_lock<fastlock> lock(time_thread_lock); std::unique_lock<fastlock> lock(time_thread_lock);
aeThreadOnline();
if (sleeping_threads >= cserver.cthreads) { if (sleeping_threads >= cserver.cthreads) {
aeThreadOffline(); aeThreadOffline();
time_thread_cv.wait(lock); time_thread_cv.wait(lock);