--- libaitsched/src/tasks.c 2019/01/14 15:58:50 1.27 +++ libaitsched/src/tasks.c 2022/11/28 23:52:35 1.29.4.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tasks.c,v 1.27 2019/01/14 15:58:50 misho Exp $ +* $Id: tasks.c,v 1.29.4.2 2022/11/28 23:52:35 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 - 2018 +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; @@ -133,6 +133,25 @@ sched_task_t * schedRead(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, int fd, void *opt_data, size_t opt_dlen) { + return schedReadExt(root, func, arg, fd, opt_data, opt_dlen, 0); +} + +/* + * schedReadExt() - Add READ I/O task to scheduler queue with custom event mask + * + * @root = root task + * @func = task execution function + * @arg = 1st func argument + * @fd = fd handle + * @opt_data = Optional data + * @opt_dlen = Optional data length + * @mask = Event mask + * return: NULL error or !=NULL new queued task + */ +sched_task_t * +schedReadExt(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, int fd, + void *opt_data, size_t opt_dlen, u_long mask) +{ sched_task_t *task; void *ptr; @@ -153,8 +172,11 @@ schedRead(sched_root_task_t * __restrict root, sched_t TASK_DATA(task) = opt_data; TASK_DATLEN(task) = opt_dlen; + TASK_HARG(task) = mask; + if (root->root_hooks.hook_add.read) - ptr = root->root_hooks.hook_add.read(task, NULL); + ptr = root->root_hooks.hook_add.read(task, + (void*) task->task_harg); else ptr = NULL; @@ -307,8 +329,12 @@ schedNode2(sched_root_task_t * __restrict root, sched_ 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; @@ -627,7 +653,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 @@ -643,7 +669,7 @@ schedAIORead(sched_root_task_t * __restrict root, sche if (aio_read(acb)) { LOGERR; - free(acb); + e_free(acb); return NULL; } @@ -686,7 +712,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 @@ -702,7 +728,7 @@ schedAIOWrite(sched_root_task_t * __restrict root, sch if (aio_write(acb)) { LOGERR; - free(acb); + e_free(acb); return NULL; } @@ -801,19 +827,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)); @@ -832,8 +858,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; } @@ -878,19 +904,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)); @@ -909,8 +935,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; }