serverAsserts on sleeping_threads, remove bare locks

Former-commit-id: 8c64ca2333d8eb2ee92d835907474ec63e127b62
This commit is contained in:
christianEQ 2021-03-24 20:44:40 +00:00
parent 9dde193c1d
commit ce8705451a

View File

@ -2514,9 +2514,11 @@ void beforeSleep(struct aeEventLoop *eventLoop) {
serverAssert(g_pserver->repl_batch_offStart < 0); serverAssert(g_pserver->repl_batch_offStart < 0);
runAndPropogateToReplicas(processClients); runAndPropogateToReplicas(processClients);
time_thread_mutex.lock(); {
std::lock_guard<std::mutex> lock(time_thread_mutex);
sleeping_threads++; sleeping_threads++;
time_thread_mutex.unlock(); serverAssert(sleeping_threads <= cserver.cthreads);
}
/* Handle precise timeouts of blocked clients. */ /* Handle precise timeouts of blocked clients. */
handleBlockedClientsTimeout(); handleBlockedClientsTimeout();
@ -6088,9 +6090,9 @@ void OnTerminate()
} }
void wakeTimeThread() { void wakeTimeThread() {
time_thread_mutex.lock(); std::lock_guard<std::mutex> lock(time_thread_mutex);
sleeping_threads--; sleeping_threads--;
time_thread_mutex.unlock(); serverAssert(sleeping_threads >= 0);
time_thread_cv.notify_one(); time_thread_cv.notify_one();
} }
@ -6099,10 +6101,12 @@ void *timeThreadMain(void*) {
delay.tv_sec = 0; delay.tv_sec = 0;
delay.tv_nsec = 100; delay.tv_nsec = 100;
while (true) { while (true) {
{
std::unique_lock<std::mutex> lock(time_thread_mutex); std::unique_lock<std::mutex> lock(time_thread_mutex);
if (sleeping_threads >= cserver.cthreads) { if (sleeping_threads >= cserver.cthreads) {
time_thread_cv.wait(lock); time_thread_cv.wait(lock);
} }
}
updateCachedTime(); updateCachedTime();
clock_nanosleep(CLOCK_REALTIME, 0, &delay, NULL); clock_nanosleep(CLOCK_REALTIME, 0, &delay, NULL);
} }