--- libaitsched/src/tasks.c 2015/07/02 22:45:00 1.26 +++ libaitsched/src/tasks.c 2018/08/20 12:03:53 1.26.12.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tasks.c,v 1.26 2015/07/02 22:45:00 misho Exp $ +* $Id: tasks.c,v 1.26.12.1 2018/08/20 12:03:53 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004 - 2015 +Copyright 2004 - 2018 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -255,6 +255,60 @@ schedNode(sched_root_task_t * __restrict root, sched_t if (root->root_hooks.hook_add.node) ptr = root->root_hooks.hook_add.node(task, NULL); + else + ptr = NULL; + + if (!ptr) + insert_task_to(task, &root->root_node); + else + task = sched_unuseTask(task); + + return task; +#endif /* KQ_SUPPORT */ +} + +/* + * schedNode2() - Add NODE task with all events to scheduler queue + * + * @root = root task + * @func = task execution function + * @arg = 1st func argument + * @fd = fd handle + * @opt_data = Optional data + * @opt_dlen = Optional data length + * return: NULL error or !=NULL new queued task + */ +sched_task_t * +schedNode2(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, int fd, + void *opt_data, size_t opt_dlen) +{ +#if SUP_ENABLE != KQ_SUPPORT + sched_SetErr(ENOTSUP, "disabled kqueue support"); + return NULL; +#else + sched_task_t *task; + void *ptr; + + if (!root || !func) + return NULL; + + /* get new task */ + if (!(task = sched_useTask(root))) + return NULL; + + TASK_FUNC(task) = func; + TASK_TYPE(task) = taskNODE; + TASK_ROOT(task) = root; + + TASK_ARG(task) = arg; + TASK_FD(task) = fd; + + TASK_DATA(task) = opt_data; + TASK_DATLEN(task) = opt_dlen; + + if (root->root_hooks.hook_add.node) + ptr = root->root_hooks.hook_add.node(task, + (void*) (NOTE_READ | NOTE_CLOSE_WRITE | NOTE_CLOSE | NOTE_OPEN)); else ptr = NULL;