--- libaitsched/src/tasks.c 2012/08/02 12:58:02 1.10.2.10 +++ libaitsched/src/tasks.c 2012/08/02 13:45:02 1.10.2.11 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tasks.c,v 1.10.2.10 2012/08/02 12:58:02 misho Exp $ +* $Id: tasks.c,v 1.10.2.11 2012/08/02 13:45:02 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -647,6 +647,60 @@ schedAIOWrite(sched_root_task_t * __restrict root, sch #ifdef EVFILT_LIO /* + * schedLIO() - Add AIO bulk tasks to scheduler queue + * + * @root = root task + * @func = task execution function + * @arg = 1st func argument + * @acbs = AIO cb structure addresses + * @opt_data = Optional data + * @opt_dlen = Optional data length + * return: NULL error or !=NULL new queued task + */ +sched_task_t * +schedLIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, + struct aiocb ** __restrict acbs, void *opt_data, size_t opt_dlen) +{ + sched_task_t *task; + void *ptr; + + if (!root || !func || !acbs || !opt_dlen) + return NULL; + + /* get new task */ + if (!(task = _sched_useTask(root))) + return NULL; + + task->task_func = func; + TASK_TYPE(task) = taskLIO; + TASK_ROOT(task) = root; + + TASK_ARG(task) = arg; + TASK_VAL(task) = (u_long) acbs; + + TASK_DATA(task) = opt_data; + TASK_DATLEN(task) = opt_dlen; + + if (root->root_hooks.hook_add.lio) + ptr = root->root_hooks.hook_add.lio(task, NULL); + else + ptr = NULL; + + if (!ptr) { +#ifdef HAVE_LIBPTHREAD + pthread_mutex_lock(&root->root_mtx[taskLIO]); +#endif + TAILQ_INSERT_TAIL(&root->root_lio, TASK_ID(task), task_node); +#ifdef HAVE_LIBPTHREAD + pthread_mutex_unlock(&root->root_mtx[taskLIO]); +#endif + } else + task = _sched_unuseTask(task); + + return task; +} + +/* * schedLIORead() - Add list of AIO read tasks to scheduler queue * * @root = root task @@ -711,7 +765,7 @@ schedLIORead(sched_root_task_t * __restrict root, sche return NULL; } - return schedAIO(root, func, arg, (void*) acb, bufs, nbufs); + return schedLIO(root, func, arg, (void*) acb, bufs, nbufs); } /* @@ -779,7 +833,7 @@ schedLIOWrite(sched_root_task_t * __restrict root, sch return NULL; } - return schedAIO(root, func, arg, (void*) acb, bufs, nbufs); + return schedLIO(root, func, arg, (void*) acb, bufs, nbufs); } #endif /* EVFILT_LIO */ #endif /* AIO_SUPPORT */