--- libaitsched/src/tasks.c 2013/05/30 09:13:52 1.16 +++ libaitsched/src/tasks.c 2013/08/15 18:40:39 1.16.6.3 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tasks.c,v 1.16 2013/05/30 09:13:52 misho Exp $ +* $Id: tasks.c,v 1.16.6.3 2013/08/15 18:40:39 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -511,7 +511,7 @@ schedSignal(sched_root_task_t * __restrict root, sched * @func = task execution function * @arg = 1st func argument * @ts = timeout argument structure, minimum alarm timer resolution is 1msec! - * @opt_data = Optional data + * @opt_data = Alarm timer ID * @opt_dlen = Optional data length * return: NULL error or !=NULL new queued task */ @@ -1322,3 +1322,56 @@ schedThread(sched_root_task_t * __restrict root, sched return task; } +/* + * schedRTC() - Add RTC task to scheduler queue + * + * @root = root task + * @func = task execution function + * @arg = 1st func argument + * @ts = timeout argument structure, minimum alarm timer resolution is 1msec! + * @opt_data = Optional RTC ID + * @opt_dlen = Optional Signal No. + * return: NULL error or !=NULL new queued task + */ +sched_task_t * +schedRTC(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; + + task->task_func = func; + TASK_TYPE(task) = taskRTC; + 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.rtc) + ptr = root->root_hooks.hook_add.rtc(task, NULL); + else + ptr = NULL; + + if (!ptr) { +#ifdef HAVE_LIBPTHREAD + pthread_mutex_lock(&root->root_mtx[taskRTC]); +#endif + TAILQ_INSERT_TAIL(&root->root_rtc, TASK_ID(task), task_node); +#ifdef HAVE_LIBPTHREAD + pthread_mutex_unlock(&root->root_mtx[taskRTC]); +#endif + } else + task = sched_unuseTask(task); + + return task; +}