--- libaitsched/src/tasks.c 2015/07/02 22:45:00 1.26 +++ libaitsched/src/tasks.c 2022/10/03 22:16:36 1.28.4.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.28.4.1 2022/10/03 22:16:36 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 - 2022 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -67,7 +67,7 @@ sched_useTask(sched_root_task_t * __restrict root) SCHED_QUNLOCK(root, taskUNUSE); if (!task) { - task = malloc(sizeof(sched_task_t)); + task = e_malloc(sizeof(sched_task_t)); if (!task) { LOGERR; return NULL; @@ -268,6 +268,64 @@ schedNode(sched_root_task_t * __restrict root, sched_t } /* + * 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) +#ifdef __FreeBSD__ + ptr = root->root_hooks.hook_add.node(task, + (void*) (NOTE_READ | NOTE_CLOSE_WRITE | NOTE_CLOSE | NOTE_OPEN)); +#else + ptr = root->root_hooks.hook_add.node(task, NULL); +#endif + else + ptr = NULL; + + if (!ptr) + insert_task_to(task, &root->root_node); + else + task = sched_unuseTask(task); + + return task; +#endif /* KQ_SUPPORT */ +} + +/* * schedProc() - Add PROC task to scheduler queue * * @root = root task @@ -573,7 +631,7 @@ schedAIORead(sched_root_task_t * __restrict root, sche } else off = offset; - if (!(acb = malloc(sizeof(struct aiocb)))) { + if (!(acb = e_malloc(sizeof(struct aiocb)))) { LOGERR; return NULL; } else @@ -589,7 +647,7 @@ schedAIORead(sched_root_task_t * __restrict root, sche if (aio_read(acb)) { LOGERR; - free(acb); + e_free(acb); return NULL; } @@ -632,7 +690,7 @@ schedAIOWrite(sched_root_task_t * __restrict root, sch } else off = offset; - if (!(acb = malloc(sizeof(struct aiocb)))) { + if (!(acb = e_malloc(sizeof(struct aiocb)))) { LOGERR; return NULL; } else @@ -648,7 +706,7 @@ schedAIOWrite(sched_root_task_t * __restrict root, sch if (aio_write(acb)) { LOGERR; - free(acb); + e_free(acb); return NULL; } @@ -747,19 +805,19 @@ schedLIORead(sched_root_task_t * __restrict root, sche } else off = offset; - if (!(acb = calloc(sizeof(void*), nbufs))) { + if (!(acb = e_calloc(sizeof(void*), nbufs))) { LOGERR; return NULL; } else memset(acb, 0, sizeof(void*) * nbufs); for (i = 0; i < nbufs; off += bufs[i++].iov_len) { - acb[i] = malloc(sizeof(struct aiocb)); + acb[i] = e_malloc(sizeof(struct aiocb)); if (!acb[i]) { LOGERR; for (i = 0; i < nbufs; i++) if (acb[i]) - free(acb[i]); - free(acb); + e_free(acb[i]); + e_free(acb); return NULL; } else memset(acb[i], 0, sizeof(struct aiocb)); @@ -778,8 +836,8 @@ schedLIORead(sched_root_task_t * __restrict root, sche LOGERR; for (i = 0; i < nbufs; i++) if (acb[i]) - free(acb[i]); - free(acb); + e_free(acb[i]); + e_free(acb); return NULL; } @@ -824,19 +882,19 @@ schedLIOWrite(sched_root_task_t * __restrict root, sch } else off = offset; - if (!(acb = calloc(sizeof(void*), nbufs))) { + if (!(acb = e_calloc(sizeof(void*), nbufs))) { LOGERR; return NULL; } else memset(acb, 0, sizeof(void*) * nbufs); for (i = 0; i < nbufs; off += bufs[i++].iov_len) { - acb[i] = malloc(sizeof(struct aiocb)); + acb[i] = e_malloc(sizeof(struct aiocb)); if (!acb[i]) { LOGERR; for (i = 0; i < nbufs; i++) if (acb[i]) - free(acb[i]); - free(acb); + e_free(acb[i]); + e_free(acb); return NULL; } else memset(acb[i], 0, sizeof(struct aiocb)); @@ -855,8 +913,8 @@ schedLIOWrite(sched_root_task_t * __restrict root, sch LOGERR; for (i = 0; i < nbufs; i++) if (acb[i]) - free(acb[i]); - free(acb); + e_free(acb[i]); + e_free(acb); return NULL; }