mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-16 00:00:02 +01:00
task: fix periodic tasks when using nanosleep()
This commit is contained in:
parent
377af00af4
commit
5f0c6194e9
1 changed files with 7 additions and 24 deletions
31
lib/task.c
31
lib/task.c
|
@ -135,18 +135,6 @@ int task_destroy(struct task *t)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if PERIODIC_TASK_IMPL == CLOCK_NANOSLEEP || PERIODIC_TASK_IMPL == NANOSLEEP
|
||||
static int time_lt(const struct timespec *lhs, const struct timespec *rhs)
|
||||
{
|
||||
if (lhs->tv_sec == rhs->tv_sec)
|
||||
return lhs->tv_nsec < rhs->tv_nsec;
|
||||
else
|
||||
return lhs->tv_sec < rhs->tv_sec;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint64_t task_wait(struct task *t)
|
||||
{
|
||||
uint64_t runs;
|
||||
|
@ -155,6 +143,13 @@ uint64_t task_wait(struct task *t)
|
|||
int ret;
|
||||
struct timespec now;
|
||||
|
||||
ret = clock_gettime(t->clock, &now);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
for (runs = 0; time_cmp(&t->next, &now) < 0; runs++)
|
||||
t->next = time_add(&t->next, &t->period);
|
||||
|
||||
#if PERIODIC_TASK_IMPL == CLOCK_NANOSLEEP
|
||||
do {
|
||||
ret = clock_nanosleep(t->clock, TIMER_ABSTIME, &t->next, NULL);
|
||||
|
@ -162,23 +157,11 @@ uint64_t task_wait(struct task *t)
|
|||
#elif PERIODIC_TASK_IMPL == NANOSLEEP
|
||||
struct timespec delta;
|
||||
|
||||
ret = clock_gettime(t->clock, &now);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
delta = time_diff(&now, &t->next);
|
||||
|
||||
ret = nanosleep(&delta, NULL);
|
||||
#endif
|
||||
if (ret < 0)
|
||||
return 0;
|
||||
|
||||
ret = clock_gettime(t->clock, &now);
|
||||
if (ret)
|
||||
return 0;
|
||||
|
||||
for (runs = 0; time_lt(&t->next, &now); runs++)
|
||||
t->next = time_add(&t->next, &t->period);
|
||||
#elif PERIODIC_TASK_IMPL == TIMERFD
|
||||
int ret;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue