--- libaitsched/src/tasks.c 2012/01/23 15:56:23 1.4.2.2 +++ libaitsched/src/tasks.c 2012/03/13 10:01:59 1.6 @@ -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.6 2012/03/13 10:01:59 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 +Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -99,6 +99,7 @@ _sched_unuseTask(sched_task_t * __restrict task) /* * schedRead() - Add READ I/O task to scheduler queue + * * @root = root task * @func = task execution function * @arg = 1st func argument @@ -155,6 +156,7 @@ schedRead(sched_root_task_t * __restrict root, sched_t /* * schedWrite() - Add WRITE I/O task to scheduler queue + * * @root = root task * @func = task execution function * @arg = 1st func argument @@ -211,22 +213,22 @@ schedWrite(sched_root_task_t * __restrict root, sched_ /* * schedTimer() - Add TIMER task to scheduler queue + * * @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 +250,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 +275,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); @@ -291,6 +293,7 @@ schedTimer(sched_root_task_t * __restrict root, sched_ /* * schedEvent() - Add EVENT task to scheduler queue + * * @root = root task * @func = task execution function * @arg = 1st func argument @@ -348,6 +351,7 @@ schedEvent(sched_root_task_t * __restrict root, sched_ /* * schedEventLo() - Add EVENT_Lo task to scheduler queue + * * @root = root task * @func = task execution function * @arg = 1st func argument @@ -404,6 +408,7 @@ schedEventLo(sched_root_task_t * __restrict root, sche /* * schedCallOnce() - Call once from scheduler + * * @root = root task * @func = task execution function * @arg = 1st func argument