Skip to content

Commit

Permalink
Service: Fix tick timer setting
Browse files Browse the repository at this point in the history
setTickInterval must set the timer as soon as it was initially set, even
before the service is fully started.
  • Loading branch information
Zirias committed Jul 24, 2024
1 parent 06d872b commit d293942
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib/core/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static int shutdownTicks;

static struct itimerval timer;
static struct itimerval otimer;
static int timerset;

typedef struct ServiceTimer
{
Expand Down Expand Up @@ -216,7 +217,7 @@ SOEXPORT int PSC_Service_setTickInterval(unsigned msec)
timer.it_interval.tv_usec = 1000U * (msec % 1000U);
timer.it_value.tv_sec = msec / 1000U;
timer.it_value.tv_usec = 1000U * (msec % 1000U);
if (running) return setitimer(ITIMER_REAL, &timer, 0);
if (timerset) return setitimer(ITIMER_REAL, &timer, 0);
return 0;
}

Expand Down Expand Up @@ -314,6 +315,7 @@ static int serviceLoop(int isRun)
PSC_Log_msg(PSC_L_ERROR, "cannot set periodic timer");
goto done;
}
timerset = 1;

PSC_Event_raise(&startup, 0, &sea);
rc = sea.rc;
Expand Down Expand Up @@ -434,6 +436,7 @@ static int serviceLoop(int isRun)
rc = EXIT_FAILURE;
}

timerset = 0;
if (setitimer(ITIMER_REAL, &otimer, 0) < 0)
{
PSC_Log_msg(PSC_L_ERROR, "cannot restore original periodic timer");
Expand Down

0 comments on commit d293942

Please sign in to comment.