--- libaitsched/src/tasks.c 2012/05/31 22:31:48 1.9 +++ libaitsched/src/tasks.c 2012/07/24 13:47:02 1.9.6.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tasks.c,v 1.9 2012/05/31 22:31:48 misho Exp $ +* $Id: tasks.c,v 1.9.6.1 2012/07/24 13:47:02 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -661,6 +661,60 @@ schedEventLo(sched_root_task_t * __restrict root, sche TAILQ_INSERT_TAIL(&root->root_eventlo, TASK_ID(task), task_node); #ifdef HAVE_LIBPTHREAD pthread_mutex_unlock(&root->root_mtx[taskEVENTLO]); +#endif + } else + task = _sched_unuseTask(task); + + return task; +} + +/* + * schedSuspend() - Add Suspended task to scheduler queue + * + * @root = root task + * @func = task execution function + * @arg = 1st func argument + * @id = Trigger ID + * @opt_data = Optional data + * @opt_dlen = Optional data length + * return: NULL error or !=NULL new queued task + */ +sched_task_t * +schedSuspend(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, u_long id, + 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) = taskSUSPEND; + TASK_ROOT(task) = root; + + TASK_ARG(task) = arg; + TASK_VAL(task) = id; + + TASK_DATA(task) = opt_data; + TASK_DATLEN(task) = opt_dlen; + + if (root->root_hooks.hook_add.suspend) + ptr = root->root_hooks.hook_add.suspend(task, NULL); + else + ptr = NULL; + + if (!ptr) { +#ifdef HAVE_LIBPTHREAD + pthread_mutex_lock(&root->root_mtx[taskSUSPEND]); +#endif + TAILQ_INSERT_TAIL(&root->root_suspend, TASK_ID(task), task_node); +#ifdef HAVE_LIBPTHREAD + pthread_mutex_unlock(&root->root_mtx[taskSUSPEND]); #endif } else task = _sched_unuseTask(task);