added condition variable to time thread; wake on afterSleep, sleep on beforeSleep
Former-commit-id: ff2f2a3aceff2ba4a74951197348d67fc39568b2
This commit is contained in:
parent
adf8ba67c8
commit
301e4f6a16
@ -61,6 +61,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <uuid/uuid.h>
|
#include <uuid/uuid.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <condition_variable>
|
||||||
#include "aelocker.h"
|
#include "aelocker.h"
|
||||||
#include "keycheck.h"
|
#include "keycheck.h"
|
||||||
#include "motd.h"
|
#include "motd.h"
|
||||||
@ -97,6 +98,10 @@ redisServer *g_pserver = &GlobalHidden::server;
|
|||||||
struct redisServerConst cserver;
|
struct redisServerConst cserver;
|
||||||
thread_local struct redisServerThreadVars *serverTL = NULL; // thread local server vars
|
thread_local struct redisServerThreadVars *serverTL = NULL; // thread local server vars
|
||||||
volatile unsigned long lru_clock; /* Server global current LRU time. */
|
volatile unsigned long lru_clock; /* Server global current LRU time. */
|
||||||
|
std::mutex time_thread_mutex;
|
||||||
|
std::condition_variable time_thread_cv;
|
||||||
|
bool time_thread_running = false;
|
||||||
|
void wakeTimeThread();
|
||||||
|
|
||||||
/* Our command table.
|
/* Our command table.
|
||||||
*
|
*
|
||||||
@ -2509,6 +2514,8 @@ 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_running = false;
|
||||||
|
|
||||||
/* Handle precise timeouts of blocked clients. */
|
/* Handle precise timeouts of blocked clients. */
|
||||||
handleBlockedClientsTimeout();
|
handleBlockedClientsTimeout();
|
||||||
|
|
||||||
@ -2655,6 +2662,8 @@ void afterSleep(struct aeEventLoop *eventLoop) {
|
|||||||
/* Aquire the modules GIL so that their threads won't touch anything. */
|
/* Aquire the modules GIL so that their threads won't touch anything. */
|
||||||
if (moduleCount()) moduleAcquireGIL(TRUE /*fServerThread*/);
|
if (moduleCount()) moduleAcquireGIL(TRUE /*fServerThread*/);
|
||||||
|
|
||||||
|
wakeTimeThread();
|
||||||
|
|
||||||
serverAssert(serverTL->gcEpoch.isReset());
|
serverAssert(serverTL->gcEpoch.isReset());
|
||||||
serverTL->gcEpoch = g_pserver->garbageCollector.startEpoch();
|
serverTL->gcEpoch = g_pserver->garbageCollector.startEpoch();
|
||||||
for (int idb = 0; idb < cserver.dbnum; ++idb)
|
for (int idb = 0; idb < cserver.dbnum; ++idb)
|
||||||
@ -5731,6 +5740,8 @@ static void sigShutdownHandler(int sig) {
|
|||||||
msg = "Received shutdown signal, scheduling shutdown...";
|
msg = "Received shutdown signal, scheduling shutdown...";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
wakeTimeThread();
|
||||||
|
|
||||||
/* SIGINT is often delivered via Ctrl+C in an interactive session.
|
/* SIGINT is often delivered via Ctrl+C in an interactive session.
|
||||||
* If we receive the signal the second time, we interpret this as
|
* If we receive the signal the second time, we interpret this as
|
||||||
* the user really wanting to quit ASAP without waiting to persist
|
* the user really wanting to quit ASAP without waiting to persist
|
||||||
@ -6076,15 +6087,24 @@ void OnTerminate()
|
|||||||
serverPanic("std::teminate() called");
|
serverPanic("std::teminate() called");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wakeTimeThread() {
|
||||||
|
time_thread_running = true;
|
||||||
|
time_thread_cv.notify_one();
|
||||||
|
}
|
||||||
|
|
||||||
void *timeThreadMain(void*) {
|
void *timeThreadMain(void*) {
|
||||||
timespec delay;
|
timespec delay;
|
||||||
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);
|
||||||
|
if (!time_thread_running) {
|
||||||
|
time_thread_cv.wait(lock);
|
||||||
|
}
|
||||||
updateCachedTime();
|
updateCachedTime();
|
||||||
clock_nanosleep(CLOCK_REALTIME, 0, &delay, NULL);
|
clock_nanosleep(CLOCK_REALTIME, 0, &delay, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *workerThreadMain(void *parg)
|
void *workerThreadMain(void *parg)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user