Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/cron/cron.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "util/rmalloc.h"

#include <time.h>
#include <errno.h>
#include <pthread.h>
#include <stdbool.h>

Expand Down Expand Up @@ -80,6 +81,10 @@ static struct timespec due_in_ms

due.tv_sec += ms / 1000;
due.tv_nsec += (ms % 1000) * 1000000;
// add the overflow seconds otherwise the time will be invalid
// and the thread will wake up immediately which lead to busy loop
due.tv_sec += due.tv_nsec / 1000000000;
due.tv_nsec %= 1000000000;

return due;
}
Expand Down Expand Up @@ -201,7 +206,8 @@ static void *Cron_Run
// sleep
struct timespec timeout = (task) ? task->due : due_in_ms(1000);
pthread_mutex_lock(&cron->condv_mutex);
pthread_cond_timedwait(&cron->condv, &cron->condv_mutex, &timeout);
int res = pthread_cond_timedwait(&cron->condv, &cron->condv_mutex, &timeout);
ASSERT(res == 0 || res == ETIMEDOUT);
pthread_mutex_unlock(&cron->condv_mutex);
}

Expand Down