Changed RM_CreateTimer to only call aePostFunction is existing aePostFunction isn't in flight
Former-commit-id: 9954f5b4a48286d07fb876fd9579801365b6c237
This commit is contained in:
parent
84dc6401c7
commit
cf122aa54d
@ -5579,6 +5579,8 @@ void RM_SetClusterFlags(RedisModuleCtx *ctx, uint64_t flags) {
|
|||||||
|
|
||||||
static rax *Timers; /* The radix tree of all the timers sorted by expire. */
|
static rax *Timers; /* The radix tree of all the timers sorted by expire. */
|
||||||
long long aeTimer = -1; /* Main event loop (ae.c) timer identifier. */
|
long long aeTimer = -1; /* Main event loop (ae.c) timer identifier. */
|
||||||
|
bool aeTimerSet = false;/* Checks whether the main event loop timer is set
|
||||||
|
or if an aePostFunction is queued up that will set it */
|
||||||
|
|
||||||
typedef void (*RedisModuleTimerProc)(RedisModuleCtx *ctx, void *data);
|
typedef void (*RedisModuleTimerProc)(RedisModuleCtx *ctx, void *data);
|
||||||
|
|
||||||
@ -5668,32 +5670,38 @@ RedisModuleTimerID RM_CreateTimer(RedisModuleCtx *ctx, mstime_t period, RedisMod
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
aePostFunction(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el, [period, key]{
|
|
||||||
/* We need to install the main event loop timer if it's not already
|
/* We need to install the main event loop timer if it's not already
|
||||||
* installed, or we may need to refresh its period if we just installed
|
* installed, or we may need to refresh its period if we just installed
|
||||||
* a timer that will expire sooner than any other else (i.e. the timer
|
* a timer that will expire sooner than any other else (i.e. the timer
|
||||||
* we just installed is the first timer in the Timers rax). */
|
* we just installed is the first timer in the Timers rax). */
|
||||||
if (aeTimer != -1) {
|
bool isFirstExpiry = false;
|
||||||
|
if (raxSize(Timers) > 0){
|
||||||
raxIterator ri;
|
raxIterator ri;
|
||||||
raxStart(&ri,Timers);
|
raxStart(&ri, Timers);
|
||||||
raxSeek(&ri,"^",NULL,0);
|
raxSeek(&ri,"^",NULL,0);
|
||||||
raxNext(&ri);
|
raxNext(&ri);
|
||||||
if (memcmp(ri.key,&key,sizeof(key)) == 0) {
|
if (memcmp(ri.key,&key,sizeof(key)) == 0)
|
||||||
/* This is the first key, we need to re-install the timer according
|
/* This is the first key, we need to re-install the timer according
|
||||||
* to the just added event. */
|
* to the just added event. */
|
||||||
aeDeleteTimeEvent(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el,aeTimer);
|
isFirstExpiry = true;
|
||||||
aeTimer = -1;
|
|
||||||
}
|
|
||||||
raxStop(&ri);
|
raxStop(&ri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Now that either we know that we either need to refresh the period of the
|
||||||
|
* recently installed timer, or that there is no timer to begin with, we must post
|
||||||
|
* a function call to install the main event timer */
|
||||||
|
if (isFirstExpiry || !aeTimerSet){
|
||||||
|
aeTimerSet = true;
|
||||||
|
aePostFunction(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el, [period, isFirstExpiry]{
|
||||||
|
/* If we deemed that this timer required a reinstall, delete it before proceeding
|
||||||
|
* to the install */
|
||||||
|
if (isFirstExpiry)
|
||||||
|
aeDeleteTimeEvent(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el,aeTimer);
|
||||||
/* If we have no main timer (the old one was invalidated, or this is the
|
/* If we have no main timer (the old one was invalidated, or this is the
|
||||||
* first module timer we have), install one. */
|
* first module timer we have), install one. */
|
||||||
if (aeTimer == -1) {
|
|
||||||
aeTimer = aeCreateTimeEvent(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el,period,moduleTimerHandler,NULL,NULL);
|
aeTimer = aeCreateTimeEvent(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el,period,moduleTimerHandler,NULL,NULL);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user