--- libaitsched/src/tasks.c 2012/05/14 12:09:13 1.7 +++ libaitsched/src/tasks.c 2012/05/30 08:07:45 1.7.4.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tasks.c,v 1.7 2012/05/14 12:09:13 misho Exp $ +* $Id: tasks.c,v 1.7.4.1 2012/05/30 08:07:45 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -204,6 +204,63 @@ schedWrite(sched_root_task_t * __restrict root, sched_ TAILQ_INSERT_TAIL(&root->root_write, task, task_node); #ifdef HAVE_LIBPTHREAD pthread_mutex_unlock(&root->root_mtx[taskWRITE]); +#endif + } else + task = _sched_unuseTask(task); + + return task; +} + +/* + * schedAlarm() - Add ALARM task to scheduler queue + * + * @root = root task + * @func = task execution function + * @arg = 1st func argument + * @ts = timeout argument structure + * @opt_data = Optional data + * @opt_dlen = Optional data length + * return: NULL error or !=NULL new queued task + */ +sched_task_t * +schedAlarm(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; + void *ptr; + + if (!root || !func) + return NULL; + + /* get new task */ + if (!(task = _sched_useTask(root))) + return NULL; + + memset(task, 0, sizeof(sched_task_t)); + task->task_id = 0; + task->task_lock = 0; + task->task_func = func; + TASK_TYPE(task) = taskALARM; + TASK_ROOT(task) = root; + + TASK_ARG(task) = arg; + TASK_TS(task) = ts; + + TASK_DATA(task) = opt_data; + TASK_DATLEN(task) = opt_dlen; + + if (root->root_hooks.hook_add.alarm) + ptr = root->root_hooks.hook_add.alarm(task, NULL); + else + ptr = NULL; + + if (!ptr) { +#ifdef HAVE_LIBPTHREAD + pthread_mutex_lock(&root->root_mtx[taskALARM]); +#endif + TAILQ_INSERT_TAIL(&root->root_alarm, task, task_node); +#ifdef HAVE_LIBPTHREAD + pthread_mutex_unlock(&root->root_mtx[taskALARM]); #endif } else task = _sched_unuseTask(task);