Merge pull request #1849 from haoyifan/timer_fix

[Timer] Initialize the last tmrCtrls.
This commit is contained in:
Jeff Tao 2020-05-24 11:38:29 +08:00 committed by GitHub
commit b128febbdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 5 deletions

View File

@ -405,19 +405,19 @@ static bool doStopTimer(tmr_obj_t* timer, uint8_t state) {
tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param); tmrTrace(fmt, timer->ctrl->label, timer->id, timer->fp, timer->param);
return reusable; return reusable;
} }
if (state != TIMER_STATE_EXPIRED) { if (state != TIMER_STATE_EXPIRED) {
// timer already stopped or cancelled, has nothing to do in this case // timer already stopped or cancelled, has nothing to do in this case
return false; return false;
} }
if (timer->executedBy == taosGetPthreadId()) { if (timer->executedBy == taosGetPthreadId()) {
// taosTmrReset is called in the timer callback, should do nothing in this // taosTmrReset is called in the timer callback, should do nothing in this
// case to avoid dead lock. note taosTmrReset must be the last statement // case to avoid dead lock. note taosTmrReset must be the last statement
// of the callback funtion, will be a bug otherwise. // of the callback funtion, will be a bug otherwise.
return false; return false;
} }
// timer callback is executing in another thread, we SHOULD wait it to stop, // timer callback is executing in another thread, we SHOULD wait it to stop,
// BUT this may result in dead lock if current thread are holding a lock which // BUT this may result in dead lock if current thread are holding a lock which
// the timer callback need to acquire. so, we HAVE TO return directly. // the timer callback need to acquire. so, we HAVE TO return directly.
@ -501,6 +501,7 @@ static void taosTmrModuleInit(void) {
tmr_ctrl_t* ctrl = tmrCtrls + i; tmr_ctrl_t* ctrl = tmrCtrls + i;
ctrl->next = ctrl + 1; ctrl->next = ctrl + 1;
} }
(tmrCtrls + taosMaxTmrCtrl - 1)->next = NULL;
unusedTmrCtrl = tmrCtrls; unusedTmrCtrl = tmrCtrls;
pthread_mutex_init(&tmrCtrlMutex, NULL); pthread_mutex_init(&tmrCtrlMutex, NULL);
@ -574,12 +575,12 @@ void taosTmrCleanUp(void* handle) {
if (numOfTmrCtrl <=0) { if (numOfTmrCtrl <=0) {
taosUninitTimer(); taosUninitTimer();
taosCleanUpScheduler(tmrQhandle); taosCleanUpScheduler(tmrQhandle);
for (int i = 0; i < tListLen(wheels); i++) { for (int i = 0; i < tListLen(wheels); i++) {
time_wheel_t* wheel = wheels + i; time_wheel_t* wheel = wheels + i;
pthread_mutex_destroy(&wheel->mutex); pthread_mutex_destroy(&wheel->mutex);
free(wheel->slots); free(wheel->slots);
} }