--- libaitsched/src/tasks.c 2012/08/02 13:56:19 1.11 +++ libaitsched/src/tasks.c 2012/08/08 08:15:24 1.11.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tasks.c,v 1.11 2012/08/02 13:56:19 misho Exp $ +* $Id: tasks.c,v 1.11.2.1 2012/08/08 08:15:24 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -979,21 +979,21 @@ schedEvent(sched_root_task_t * __restrict root, sched_ /* - * schedEventLo() - Add EVENT_Lo task to scheduler queue + * schedTask() - Add regular task to scheduler queue * * @root = root task * @func = task execution function * @arg = 1st func argument - * @val = additional func argument + * @prio = regular task priority, 0 is hi priority for regular tasks * @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, +schedTask(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, u_long prio, void *opt_data, size_t opt_dlen) { - sched_task_t *task; + sched_task_t *task, *tmp, *t = NULL; void *ptr; if (!root || !func) @@ -1004,27 +1004,33 @@ schedEventLo(sched_root_task_t * __restrict root, sche return NULL; task->task_func = func; - TASK_TYPE(task) = taskEVENT; + TASK_TYPE(task) = taskTASK; TASK_ROOT(task) = root; TASK_ARG(task) = arg; - TASK_VAL(task) = val; + TASK_VAL(task) = prio; 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); + if (root->root_hooks.hook_add.task) + ptr = root->root_hooks.hook_add.task(task, NULL); else ptr = NULL; if (!ptr) { #ifdef HAVE_LIBPTHREAD - pthread_mutex_lock(&root->root_mtx[taskEVENTLO]); + pthread_mutex_lock(&root->root_mtx[taskTASK]); #endif - TAILQ_INSERT_TAIL(&root->root_eventlo, TASK_ID(task), task_node); + TAILQ_FOREACH_SAFE(t, &root->root_task, task_node, tmp) + if (TASK_VAL(task) < TASK_VAL(t)) + break; + if (!t) + TAILQ_INSERT_TAIL(&root->root_task, TASK_ID(task), task_node); + else + TAILQ_INSERT_BEFORE(t, TASK_ID(task), task_node); #ifdef HAVE_LIBPTHREAD - pthread_mutex_unlock(&root->root_mtx[taskEVENTLO]); + pthread_mutex_unlock(&root->root_mtx[taskTASK]); #endif } else task = _sched_unuseTask(task);