Now post entire timer installation process as one function to make atomic with respect to global locks
Former-commit-id: 53936661c88bd7eac88308afc75c510134a8e044
This commit is contained in:
parent
e3eec7e37c
commit
73e8825266
@ -5668,30 +5668,32 @@ RedisModuleTimerID RM_CreateTimer(RedisModuleCtx *ctx, mstime_t period, RedisMod
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We need to install the main event loop timer if it's not already
|
aePostFunction(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el, [period, key]{
|
||||||
* installed, or we may need to refresh its period if we just installed
|
/* We need to install the main event loop timer if it's not already
|
||||||
* a timer that will expire sooner than any other else (i.e. the timer
|
* installed, or we may need to refresh its period if we just installed
|
||||||
* we just installed is the first timer in the Timers rax). */
|
* a timer that will expire sooner than any other else (i.e. the timer
|
||||||
if (aeTimer != -1) {
|
* we just installed is the first timer in the Timers rax). */
|
||||||
raxIterator ri;
|
if (aeTimer != -1) {
|
||||||
raxStart(&ri,Timers);
|
raxIterator ri;
|
||||||
raxSeek(&ri,"^",NULL,0);
|
raxStart(&ri,Timers);
|
||||||
raxNext(&ri);
|
raxSeek(&ri,"^",NULL,0);
|
||||||
if (memcmp(ri.key,&key,sizeof(key)) == 0) {
|
raxNext(&ri);
|
||||||
/* This is the first key, we need to re-install the timer according
|
if (memcmp(ri.key,&key,sizeof(key)) == 0) {
|
||||||
* to the just added event. */
|
/* This is the first key, we need to re-install the timer according
|
||||||
aePostFunction(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el, [period]{
|
* to the just added event. */
|
||||||
aeDeleteTimeEvent(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el,aeTimer);
|
aeDeleteTimeEvent(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el,aeTimer);
|
||||||
aeTimer = aeCreateTimeEvent(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el,period,moduleTimerHandler,NULL,NULL);
|
aeTimer = -1;
|
||||||
});
|
}
|
||||||
|
raxStop(&ri);
|
||||||
}
|
}
|
||||||
raxStop(&ri);
|
|
||||||
} else {
|
/* If we have no main timer (the old one was invalidated, or this is the
|
||||||
/* If we have no main timer because this is the first module timer we have, install one. */
|
* first module timer we have), install one. */
|
||||||
aePostFunction(g_pserver->rgthreadvar[IDX_EVENT_LOOP_MAIN].el, [period]{
|
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