--- libaitsched/src/tasks.c 2012/01/23 15:56:23 1.4.2.2 +++ libaitsched/src/tasks.c 2012/01/24 15:29:09 1.4.2.4 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tasks.c,v 1.4.2.2 2012/01/23 15:56:23 misho Exp $ +* $Id: tasks.c,v 1.4.2.4 2012/01/24 15:29:09 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -214,19 +214,18 @@ schedWrite(sched_root_task_t * __restrict root, sched_ * @root = root task * @func = task execution function * @arg = 1st func argument - * @tv = timeout argument structure + * @ts = timeout argument structure * @opt_data = Optional data * @opt_dlen = Optional data length * return: NULL error or !=NULL new queued task */ sched_task_t * -schedTimer(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, struct timeval tv, +schedTimer(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, struct timespec ts, void *opt_data, size_t opt_dlen) { sched_task_t *task, *t = NULL; void *ptr; - struct timeval now; - struct timespec nw; + struct timespec now; if (!root || !func) return NULL; @@ -248,17 +247,17 @@ schedTimer(sched_root_task_t * __restrict root, sched_ TASK_DATLEN(task) = opt_dlen; /* calculate timeval structure */ - clock_gettime(CLOCK_MONOTONIC, &nw); - now.tv_sec = nw.tv_sec + tv.tv_sec; - now.tv_usec = nw.tv_nsec / 1000 + tv.tv_usec; - if (now.tv_usec >= 1000000) { + clock_gettime(CLOCK_MONOTONIC, &now); + now.tv_sec += ts.tv_sec; + now.tv_nsec += ts.tv_nsec; + if (now.tv_nsec >= 1000000000L) { now.tv_sec++; - now.tv_usec -= 1000000; - } else if (now.tv_usec < 0) { + now.tv_nsec -= 1000000000L; + } else if (now.tv_nsec < 0) { now.tv_sec--; - now.tv_usec += 1000000; + now.tv_nsec += 1000000000L; } - TASK_TV(task) = now; + TASK_TS(task) = now; if (root->root_hooks.hook_add.timer) ptr = root->root_hooks.hook_add.timer(task, NULL); @@ -273,7 +272,7 @@ schedTimer(sched_root_task_t * __restrict root, sched_ TAILQ_INSERT_TAIL(&root->root_timer, task, task_node); #else TAILQ_FOREACH(t, &root->root_timer, task_node) - if (timercmp(&TASK_TV(task), &TASK_TV(t), -) < 1) + if (sched_timespeccmp(&TASK_TS(task), &TASK_TS(t), -) < 1) break; if (!t) TAILQ_INSERT_TAIL(&root->root_timer, task, task_node);