static int SetTimerPeriod()

in Tutorials/ErrorReporting/Stage2/eventloop_timer_utilities.c [17:33]


static int SetTimerPeriod(int timerFd, const struct timespec *initial,
                          const struct timespec *repeat);

static int SetTimerPeriod(int timerFd, const struct timespec *initial,
                          const struct timespec *repeat)
{
    static const struct timespec nullTimeSpec = {.tv_sec = 0, .tv_nsec = 0};
    struct itimerspec newValue = {.it_value = initial ? *initial : nullTimeSpec,
                                  .it_interval = repeat ? *repeat : nullTimeSpec};

    if (timerfd_settime(timerFd, /* flags */ 0, &newValue, /* old_value */ NULL) == -1) {
        Log_Debug("ERROR: Could not set timer period: %s (%d).\n", strerror(errno), errno);
        return -1;
    }

    return 0;
}