--- libaitsched/src/tasks.c 2012/01/08 03:50:11 1.4.2.1 +++ 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.1 2012/01/08 03:50:11 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 @@ -103,10 +103,13 @@ _sched_unuseTask(sched_task_t * __restrict task) * @func = task execution function * @arg = 1st func argument * @fd = fd handle + * @opt_data = Optional data + * @opt_dlen = Optional data length * return: NULL error or !=NULL new queued task */ sched_task_t * -schedRead(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, int fd) +schedRead(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, int fd, + void *opt_data, size_t opt_dlen) { sched_task_t *task; void *ptr; @@ -128,6 +131,9 @@ schedRead(sched_root_task_t * __restrict root, sched_t TASK_ARG(task) = arg; TASK_FD(task) = fd; + TASK_DATA(task) = opt_data; + TASK_DATLEN(task) = opt_dlen; + if (root->root_hooks.hook_add.read) ptr = root->root_hooks.hook_add.read(task, NULL); else @@ -153,10 +159,13 @@ schedRead(sched_root_task_t * __restrict root, sched_t * @func = task execution function * @arg = 1st func argument * @fd = fd handle + * @opt_data = Optional data + * @opt_dlen = Optional data length * return: NULL error or !=NULL new queued task */ sched_task_t * -schedWrite(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, int fd) +schedWrite(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, int fd, + void *opt_data, size_t opt_dlen) { sched_task_t *task; void *ptr; @@ -178,6 +187,9 @@ schedWrite(sched_root_task_t * __restrict root, sched_ TASK_ARG(task) = arg; TASK_FD(task) = fd; + TASK_DATA(task) = opt_data; + TASK_DATLEN(task) = opt_dlen; + if (root->root_hooks.hook_add.write) ptr = root->root_hooks.hook_add.write(task, NULL); else @@ -202,16 +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; @@ -229,18 +243,21 @@ schedTimer(sched_root_task_t * __restrict root, sched_ TASK_ARG(task) = arg; + TASK_DATA(task) = opt_data; + 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); @@ -255,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); @@ -277,10 +294,13 @@ schedTimer(sched_root_task_t * __restrict root, sched_ * @func = task execution function * @arg = 1st func argument * @val = additional func argument + * @opt_data = Optional data + * @opt_dlen = Optional data length * return: NULL error or !=NULL new queued task */ sched_task_t * -schedEvent(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, u_long val) +schedEvent(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, u_long val, + void *opt_data, size_t opt_dlen) { sched_task_t *task; void *ptr; @@ -302,6 +322,9 @@ schedEvent(sched_root_task_t * __restrict root, sched_ TASK_ARG(task) = arg; TASK_VAL(task) = val; + TASK_DATA(task) = opt_data; + TASK_DATLEN(task) = opt_dlen; + if (root->root_hooks.hook_add.event) ptr = root->root_hooks.hook_add.event(task, NULL); else @@ -328,10 +351,13 @@ schedEvent(sched_root_task_t * __restrict root, sched_ * @func = task execution function * @arg = 1st func argument * @val = additional func argument + * @opt_data = Optional data + * @opt_dlen = Optional data length * return: NULL error or !=NULL new queued task */ sched_task_t * -schedEventLo(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, u_long val) +schedEventLo(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, u_long val, + void *opt_data, size_t opt_dlen) { sched_task_t *task; void *ptr; @@ -353,6 +379,9 @@ schedEventLo(sched_root_task_t * __restrict root, sche TASK_ARG(task) = arg; TASK_VAL(task) = val; + TASK_DATA(task) = opt_data; + TASK_DATLEN(task) = opt_dlen; + if (root->root_hooks.hook_add.eventlo) ptr = root->root_hooks.hook_add.eventlo(task, NULL); else @@ -378,10 +407,13 @@ schedEventLo(sched_root_task_t * __restrict root, sche * @func = task execution function * @arg = 1st func argument * @val = additional func argument + * @opt_data = Optional data + * @opt_dlen = Optional data length * return: return value from called func */ sched_task_t * -schedCallOnce(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, u_long val) +schedCallOnce(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, u_long val, + void *opt_data, size_t opt_dlen) { sched_task_t *task; void *ret; @@ -402,6 +434,9 @@ schedCallOnce(sched_root_task_t * __restrict root, sch TASK_ARG(task) = arg; TASK_VAL(task) = val; + + TASK_DATA(task) = opt_data; + TASK_DATLEN(task) = opt_dlen; ret = schedCall(task);