Annotation of libaitsched/inc/aitsched.h, revision 1.13.2.1

1.1       misho       1: /*************************************************************************
                      2: * (C) 2011 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
                      3: *  by Michael Pounov <misho@openbsd-bg.org>
                      4: *
                      5: * $Author: misho $
1.13.2.1! misho       6: * $Id: aitsched.h,v 1.13 2012/08/08 08:25:39 misho Exp $
1.1       misho       7: *
                      8: **************************************************************************
                      9: The ELWIX and AITNET software is distributed under the following
                     10: terms:
                     11: 
                     12: All of the documentation and software included in the ELWIX and AITNET
                     13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
                     14: 
1.6       misho      15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
1.1       misho      16:        by Michael Pounov <misho@elwix.org>.  All rights reserved.
                     17: 
                     18: Redistribution and use in source and binary forms, with or without
                     19: modification, are permitted provided that the following conditions
                     20: are met:
                     21: 1. Redistributions of source code must retain the above copyright
                     22:    notice, this list of conditions and the following disclaimer.
                     23: 2. Redistributions in binary form must reproduce the above copyright
                     24:    notice, this list of conditions and the following disclaimer in the
                     25:    documentation and/or other materials provided with the distribution.
                     26: 3. All advertising materials mentioning features or use of this software
                     27:    must display the following acknowledgement:
                     28: This product includes software developed by Michael Pounov <misho@elwix.org>
                     29: ELWIX - Embedded LightWeight unIX and its contributors.
                     30: 4. Neither the name of AITNET nor the names of its contributors
                     31:    may be used to endorse or promote products derived from this software
                     32:    without specific prior written permission.
                     33: 
                     34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
                     35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     37: ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     44: SUCH DAMAGE.
                     45: */
                     46: #ifndef __AITSCHED_H
                     47: #define __AITSCHED_H
                     48: 
                     49: 
1.2       misho      50: #include <sys/types.h>
                     51: #include <sys/queue.h>
1.12      misho      52: #include <sys/event.h>
1.2       misho      53: #include <sys/uio.h>
1.3       misho      54: #include <stdint.h>
1.5       misho      55: #include <pthread.h>
1.12      misho      56: #ifdef EVFILT_LIO
                     57: #include <aio.h>
                     58: #endif
1.2       misho      59: 
                     60: 
1.1       misho      61: /* criteria type */
1.10      misho      62: #define CRITERIA_ANY   0
                     63: #define CRITERIA_CALL  1
                     64: #define CRITERIA_ARG   2
                     65: #define CRITERIA_FD    3
                     66: #define CRITERIA_VAL   4
                     67: #define CRITERIA_TS    5
                     68: #define CRITERIA_DATA  6
1.11      misho      69: #define CRITERIA_ID    7
1.1       misho      70: 
                     71: 
                     72: /* early declaration for root & task */
                     73: typedef struct sched_Task      sched_task_t;
                     74: typedef struct sched_RootTask  sched_root_task_t;
                     75: 
                     76: typedef enum {
                     77:        taskREAD = 0,
                     78:        taskWRITE,
                     79:        taskTIMER,
1.10      misho      80:        taskALARM,
                     81:        taskNODE,
                     82:        taskPROC,
1.12      misho      83:        taskSIGNAL,
                     84:        taskAIO,
                     85:        taskLIO,
1.10      misho      86:        taskUSER,
1.9       misho      87:        taskEVENT,
1.13      misho      88:        taskTASK,
1.11      misho      89:        taskSUSPEND, 
1.1       misho      90:        taskREADY,
                     91:        taskUNUSE,
                     92:        taskMAX
                     93: } sched_task_type_t;
                     94: 
                     95: /* hooks */
                     96: typedef void *(*sched_hook_func_t)(void *, void *);
                     97: struct sched_HooksTask {
                     98:        struct {
                     99:                /* read(sched_task_t *task, NULL) -> int */
                    100:                sched_hook_func_t       read;
                    101:                /* write(sched_task_t *task, NULL) -> int */
                    102:                sched_hook_func_t       write;
1.10      misho     103:                /* timer(sched_task_t *task, struct timespec *ts) -> int */
                    104:                sched_hook_func_t       timer;
                    105:                /* alarm(sched_task_t *task, NULL) -> int */
                    106:                sched_hook_func_t       alarm;
                    107:                /* node(sched_task_t *task, NULL) -> int */
                    108:                sched_hook_func_t       node;
                    109:                /* proc(sched_task_t *task, NULL) -> int */
                    110:                sched_hook_func_t       proc;
1.12      misho     111:                /* signal(sched_task_t *task, NULL) -> int */
                    112:                sched_hook_func_t       signal;
                    113:                /* aio(sched_task_t *task, NULL) -> int */
                    114:                sched_hook_func_t       aio;
                    115:                /* lio(sched_task_t *task, NULL) -> int */
                    116:                sched_hook_func_t       lio;
1.10      misho     117:                /* user(sched_task_t *task, NULL) -> int */
                    118:                sched_hook_func_t       user;
1.1       misho     119:                /* event(sched_task_t *task, NULL) -> int */
                    120:                sched_hook_func_t       event;
1.13      misho     121:                /* task(sched_task_t *task, NULL) -> int */
                    122:                sched_hook_func_t       task;
1.11      misho     123:                /* suspend(sched_task_t *task, NULL) -> int */
                    124:                sched_hook_func_t       suspend;
1.1       misho     125:        }       hook_add;
                    126:        struct {
                    127:                /* cancel(sched_task_t *task, NULL) -> int */
                    128:                sched_hook_func_t       cancel;
1.11      misho     129:                /* resume(sched_task_t *task, NULL) -> int */
                    130:                sched_hook_func_t       resume;
1.1       misho     131:                /* run(sched_root_task_t *root, NULL) -> int */
                    132:                sched_hook_func_t       run;
                    133:                /* fetch(sched_root_task_t *root, NULL) -> sched_task_t* */
                    134:                sched_hook_func_t       fetch;
1.3       misho     135:                /* exception(sched_root_task_t *root, NULL) -> int */
                    136:                sched_hook_func_t       exception;
1.6       misho     137:                /* condition(sched_root_task_t *root, intptr_t *stopValue) -> int */
                    138:                sched_hook_func_t       condition;
1.1       misho     139:        }       hook_exec;
                    140:        struct {
                    141:                /* init(sched_root_task_t *root, void *data) -> int */
                    142:                sched_hook_func_t       init;
                    143:                /* fini(sched_root_task_t *root, NULL) -> int */
                    144:                sched_hook_func_t       fini;
1.3       misho     145:                /* error(sched_root_task_t *root, int errno) -> int */
                    146:                sched_hook_func_t       error;
1.1       misho     147:        }       hook_root;
                    148: };
                    149: typedef struct sched_HooksTask hooks_task_t;
                    150: 
                    151: /* task callback, like pthread callback! */
1.2       misho     152: typedef void *(*sched_task_func_t)(sched_task_t * /* current task data*/);
1.1       misho     153: 
1.4       misho     154: /* task lock helpers */
1.10      misho     155: #define TASK_LOCK(x)           ((x)->task_lock = 42)
1.4       misho     156: #define TASK_UNLOCK(x)         ((x)->task_lock ^= (x)->task_lock)
                    157: #define TASK_ISLOCKED(x)       ((x)->task_lock)
                    158: 
1.1       misho     159: /* task & queue */
                    160: struct sched_Task {
1.4       misho     161:        volatile int                    task_lock;
1.10      misho     162:        uintptr_t                       task_id;
                    163: #define TASK_ID(x)     ((struct sched_Task*) (x)->task_id)
1.1       misho     164:        sched_task_type_t               task_type;
1.5       misho     165: #define TASK_TYPE(x)   (x)->task_type
1.1       misho     166: 
                    167:        sched_root_task_t               *task_root;
1.2       misho     168: #define TASK_ROOT(x)   (x)->task_root
1.1       misho     169:        sched_task_func_t               task_func;
1.8       misho     170: #define TASK_FUNC(x)   (x)->task_func
1.1       misho     171: 
                    172:        void                            *task_arg;
                    173:        union {
                    174:                unsigned long   v;
1.3       misho     175:                intptr_t        fd;
1.5       misho     176:                struct timespec ts;
1.1       misho     177:        }                               task_val;
                    178: #define TASK_ARG(x)    (x)->task_arg
                    179: #define TASK_VAL(x)    (x)->task_val.v
                    180: #define TASK_FD(x)     (x)->task_val.fd
1.5       misho     181: #define TASK_TS(x)     (x)->task_val.ts
1.1       misho     182: 
                    183:        struct iovec                    task_data;
                    184: #define TASK_DATA(x)   (x)->task_data.iov_base
                    185: #define TASK_DATLEN(x) (x)->task_data.iov_len
                    186: 
                    187:        TAILQ_ENTRY(sched_Task)         task_node;
                    188: };
                    189: typedef TAILQ_HEAD(, sched_Task) sched_queue_t;
1.5       misho     190: #define TASK_DATA_SET(x, _dp, _dl)     do { \
                    191:                                                if ((x)) { \
                    192:                                                        (x)->task_data.iov_base = (_dp); \
                    193:                                                        (x)->task_data.iov_len = _dl; \
                    194:                                                } \
                    195:                                        while (0)
1.1       misho     196: 
                    197: /* root task */
                    198: struct sched_RootTask {
                    199:        int             root_kq;
1.13.2.1! misho     200:        unsigned long   root_miss;
1.5       misho     201:        struct timespec root_wait;
                    202:        struct timespec root_poll;
1.6       misho     203:        intptr_t        root_cond;
1.12      misho     204:        void            *root_ret;
1.6       misho     205: 
1.5       misho     206:        pthread_mutex_t root_mtx[taskMAX];
1.1       misho     207: 
                    208:        sched_queue_t   root_read;
                    209:        sched_queue_t   root_write;
                    210:        sched_queue_t   root_timer;
1.9       misho     211:        sched_queue_t   root_alarm;
1.10      misho     212:        sched_queue_t   root_node;
                    213:        sched_queue_t   root_proc;
1.12      misho     214:        sched_queue_t   root_signal;
                    215:        sched_queue_t   root_aio;
                    216:        sched_queue_t   root_lio;
1.10      misho     217:        sched_queue_t   root_user;
1.1       misho     218:        sched_queue_t   root_event;
1.13      misho     219:        sched_queue_t   root_task;
1.11      misho     220:        sched_queue_t   root_suspend;
1.1       misho     221:        sched_queue_t   root_ready;
                    222:        sched_queue_t   root_unuse;
                    223: 
                    224:        hooks_task_t    root_hooks;
                    225:        struct iovec    root_data;
                    226: #define ROOT_DATA(x)   (x)->root_data.iov_base
                    227: #define ROOT_DATLEN(x) (x)->root_data.iov_len
                    228: };
1.7       misho     229: #define ROOT_QUEUE_EMPTY(x, _q)        TAILQ_EMPTY(&((x)->root_##_q))
1.12      misho     230: #define ROOT_RETURN(x) (x)->root_ret
1.1       misho     231: 
                    232: 
1.2       misho     233: inline int sched_GetErrno();
                    234: inline const char *sched_GetError();
                    235: 
                    236: 
1.1       misho     237: /*
                    238:  * schedInit() - Init scheduler
1.6       misho     239:  *
1.1       misho     240:  * @data = optional data if !=NULL
                    241:  * @datlen = data len if data is set
                    242:  * return: allocated root task if ok or NULL error
                    243:  */
                    244: sched_root_task_t *schedInit(void ** __restrict data, size_t datlen);
1.2       misho     245: #define schedBegin()   schedInit((void**) &schedRegisterHooks, 0)
1.1       misho     246: /*
                    247:  * schedEnd() - End scheduler & free all resources
1.6       misho     248:  *
1.1       misho     249:  * @root = root task
                    250:  * return: -1 error or 0 ok
                    251:  */
1.2       misho     252: int schedEnd(sched_root_task_t ** __restrict root);
1.1       misho     253: /*
1.2       misho     254:  * schedRegisterHooks() - Register IO handles and bind tasks to it
1.6       misho     255:  *
1.1       misho     256:  * @root = root task
                    257:  * return: -1 error or 0 ok
                    258:  */
1.2       misho     259: int schedRegisterHooks(sched_root_task_t * __restrict root);
1.1       misho     260: /*
1.5       misho     261:  * schedPolling() - Polling timeout period if no timer task is present
1.6       misho     262:  *
1.5       misho     263:  * @root = root task
                    264:  * @ts = timeout polling period, if ==NULL INFINIT timeout
                    265:  * @tsold = old timeout polling if !=NULL
                    266:  * return: -1 error or 0 ok
                    267:  */
                    268: inline int schedPolling(sched_root_task_t * __restrict root, 
                    269:                struct timespec * __restrict ts, struct timespec * __restrict tsold);
                    270: /*
1.6       misho     271:  * schedTermCondition() - Activate hook for scheduler condition kill
                    272:  *
                    273:  * @root = root task
                    274:  * @condValue = condition value, kill schedRun() if condValue == killState
1.13      misho     275:  * return: -1 error or 0 ok
1.6       misho     276:  */
                    277: inline int schedTermCondition(sched_root_task_t * __restrict root, intptr_t condValue);
                    278: /*
1.1       misho     279:  * schedCall() - Call task execution function
1.6       misho     280:  *
1.1       misho     281:  * @task = current task
                    282:  * return: !=NULL error or =NULL ok
                    283:  */
                    284: inline void *schedCall(sched_task_t * __restrict task);
                    285: /*
                    286:  * schedFetch() - Fetch ready task
1.6       misho     287:  *
1.1       misho     288:  * @root = root task
                    289:  * return: =NULL error or !=NULL ready task
                    290:  */
                    291: inline void *schedFetch(sched_root_task_t * __restrict root);
                    292: /*
                    293:  * schedRun() - Scheduler *run loop*
1.6       misho     294:  *
1.1       misho     295:  * @root = root task
1.2       misho     296:  * @killState = kill condition variable, if !=0 stop scheduler loop
1.1       misho     297:  * return: -1 error or 0 ok
                    298:  */
1.7       misho     299: int schedRun(sched_root_task_t *root, volatile intptr_t * __restrict killState);
1.1       misho     300: /*
                    301:  * schedCancel() - Cancel task from scheduler
1.6       misho     302:  *
1.1       misho     303:  * @task = task
                    304:  * return: -1 error or 0 ok
                    305:  */
                    306: int schedCancel(sched_task_t * __restrict task);
                    307: /*
                    308:  * schedCancelby() - Cancel task from scheduler by criteria
1.6       misho     309:  *
1.1       misho     310:  * @root = root task
1.5       misho     311:  * @type = cancel from queue type, if =taskMAX cancel same task from all queues
1.10      misho     312:  * @criteria = find task by criteria 
1.11      misho     313:  *     [CRITERIA_ANY|CRITERIA_CALL|CRITERIA_ARG|CRITERIA_FD|CRITERIA_VAL|CRITERIA_ID|CRITERIA_TS|CRITERIA_DATA]
1.1       misho     314:  * @param = search parameter
                    315:  * @hook = custom cleanup hook function, may be NULL
1.3       misho     316:  * return: -1 error, -2 error in sub-stage cancel execution, -3 error from custom hook or 0 ok
1.1       misho     317:  */
1.5       misho     318: int schedCancelby(sched_root_task_t * __restrict root, sched_task_type_t type, 
1.1       misho     319:                u_char criteria, void *param, sched_hook_func_t hook);
                    320: 
                    321: 
                    322: /*
1.2       misho     323:  * schedRead() - Add READ I/O task to scheduler queue
1.6       misho     324:  *
1.1       misho     325:  * @root = root task
                    326:  * @func = task execution function
                    327:  * @arg = 1st func argument
1.2       misho     328:  * @fd = fd handle
1.5       misho     329:  * @opt_data = Optional data
                    330:  * @opt_dlen = Optional data length
1.1       misho     331:  * return: NULL error or !=NULL new queued task
                    332:  */
1.5       misho     333: sched_task_t *schedRead(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    334:                int fd, void *opt_data, size_t opt_dlen);
1.8       misho     335: #define schedReadSelf(x)       schedRead(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    336:                TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.1       misho     337: /*
1.2       misho     338:  * schedWrite() - Add WRITE I/O task to scheduler queue
1.6       misho     339:  *
1.1       misho     340:  * @root = root task
                    341:  * @func = task execution function
                    342:  * @arg = 1st func argument
1.2       misho     343:  * @fd = fd handle
1.5       misho     344:  * @opt_data = Optional data
                    345:  * @opt_dlen = Optional data length
1.1       misho     346:  * return: NULL error or !=NULL new queued task
                    347:  */
1.5       misho     348: sched_task_t *schedWrite(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    349:                int fd, void *opt_data, size_t opt_dlen);
1.8       misho     350: #define schedWriteSelf(x)      schedWrite(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    351:                TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.1       misho     352: /*
1.9       misho     353:  * schedAlarm() - Add ALARM task to scheduler queue
                    354:  *
                    355:  * @root = root task
                    356:  * @func = task execution function
                    357:  * @arg = 1st func argument
                    358:  * @ts = timeout argument structure, minimum alarm timer resolution is 1msec!
                    359:  * @opt_data = Optional data
                    360:  * @opt_dlen = Optional data length
                    361:  * return: NULL error or !=NULL new queued task
                    362:  */
                    363: sched_task_t *schedAlarm(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    364:                struct timespec ts, void *opt_data, size_t opt_dlen);
                    365: #define schedAlarmSelf(x)      schedAlarm(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    366:                TASK_TS((x)), TASK_DATA((x)), TASK_DATLEN((x)))
                    367: /*
1.10      misho     368:  * schedNode() - Add NODE task to scheduler queue
                    369:  *
                    370:  * @root = root task
                    371:  * @func = task execution function
                    372:  * @arg = 1st func argument
                    373:  * @fd = fd handle
                    374:  * @opt_data = Optional data
                    375:  * @opt_dlen = Optional data length
                    376:  * return: NULL error or !=NULL new queued task
                    377:  */
                    378: sched_task_t *schedNode(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    379:                int fd, void *opt_data, size_t opt_dlen);
                    380: #define schedNodeSelf(x)       schedNode(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    381:                TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
                    382: /*
                    383:  * schedProc() - Add PROC task to scheduler queue
                    384:  *
                    385:  * @root = root task
                    386:  * @func = task execution function
                    387:  * @arg = 1st func argument
                    388:  * @pid = PID
                    389:  * @opt_data = Optional data
                    390:  * @opt_dlen = Optional data length
                    391:  * return: NULL error or !=NULL new queued task
                    392:  */
                    393: sched_task_t *schedProc(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    394:                unsigned long pid, void *opt_data, size_t opt_dlen);
                    395: #define schedProcSelf(x)       schedProc(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    396:                TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
                    397: /*
                    398:  * schedSignal() - Add SIGNAL task to scheduler queue
                    399:  *
                    400:  * @root = root task
                    401:  * @func = task execution function
                    402:  * @arg = 1st func argument
                    403:  * @sig = Signal
                    404:  * @opt_data = Optional data
                    405:  * @opt_dlen = Optional data length
                    406:  * return: NULL error or !=NULL new queued task
                    407:  */
                    408: sched_task_t *schedSignal(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    409:                unsigned long sig, void *opt_data, size_t opt_dlen);
                    410: #define schedSignalSelf(x)     schedSignal(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    411:                TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
                    412: 
1.12      misho     413: #ifdef EVFILT_LIO
                    414: /*
                    415:  * schedAIO() - Add AIO task to scheduler queue
                    416:  *
                    417:  * @root = root task
                    418:  * @func = task execution function
                    419:  * @arg = 1st func argument
                    420:  * @acb = AIO cb structure address
                    421:  * @opt_data = Optional data
                    422:  * @opt_dlen = Optional data length
                    423:  * return: NULL error or !=NULL new queued task
                    424:  */
                    425: sched_task_t *schedAIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    426:                struct aiocb * __restrict acb, void *opt_data, size_t opt_dlen);
                    427: /*
                    428:  * schedAIORead() - Add AIO read task to scheduler queue
                    429:  *
                    430:  * @root = root task
                    431:  * @func = task execution function
                    432:  * @arg = 1st func argument
                    433:  * @fd = file descriptor
                    434:  * @buffer = Buffer
                    435:  * @buflen = Buffer length
                    436:  * @offset = Offset from start of file, if =-1 from current position
                    437:  * return: NULL error or !=NULL new queued task
                    438:  */
                    439: inline sched_task_t *schedAIORead(sched_root_task_t * __restrict root, sched_task_func_t func, 
                    440:                void *arg, int fd, void *buffer, size_t buflen, off_t offset);
                    441: /*
                    442:  * schedAIOWrite() - Add AIO write task to scheduler queue
                    443:  *
                    444:  * @root = root task
                    445:  * @func = task execution function
                    446:  * @arg = 1st func argument
                    447:  * @fd = file descriptor
                    448:  * @buffer = Buffer
                    449:  * @buflen = Buffer length
                    450:  * @offset = Offset from start of file, if =-1 from current position
                    451:  * return: NULL error or !=NULL new queued task
                    452:  */
                    453: inline sched_task_t *schedAIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func, 
                    454:                void *arg, int fd, void *buffer, size_t buflen, off_t offset);
                    455: 
                    456: /*
                    457:  * schedLIO() - Add AIO bulk tasks to scheduler queue
                    458:  *
                    459:  * @root = root task
                    460:  * @func = task execution function
                    461:  * @arg = 1st func argument
                    462:  * @acbs = AIO cb structure addresses
                    463:  * @opt_data = Optional data
                    464:  * @opt_dlen = Optional data length
                    465:  * return: NULL error or !=NULL new queued task
                    466:  */
                    467: sched_task_t *schedLIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    468:                struct aiocb ** __restrict acbs, void *opt_data, size_t opt_dlen);
                    469: /*
                    470:  * schedLIORead() - Add list of AIO read tasks to scheduler queue
                    471:  *
                    472:  * @root = root task
                    473:  * @func = task execution function
                    474:  * @arg = 1st func argument
                    475:  * @fd = file descriptor
                    476:  * @bufs = Buffer's list
                    477:  * @nbufs = Number of Buffers
                    478:  * @offset = Offset from start of file, if =-1 from current position
                    479:  * return: NULL error or !=NULL new queued task
                    480:  */
                    481: inline sched_task_t *schedLIORead(sched_root_task_t * __restrict root, sched_task_func_t func, 
                    482:                void *arg, int fd, struct iovec *bufs, size_t nbufs, off_t offset);
                    483: /*
                    484:  * schedLIOWrite() - Add list of AIO write tasks to scheduler queue
                    485:  *
                    486:  * @root = root task
                    487:  * @func = task execution function
                    488:  * @arg = 1st func argument
                    489:  * @fd = file descriptor
                    490:  * @bufs = Buffer's list
                    491:  * @nbufs = Number of Buffers
                    492:  * @offset = Offset from start of file, if =-1 from current position
                    493:  * return: NULL error or !=NULL new queued task
                    494:  */
                    495: inline sched_task_t *schedLIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func, 
                    496:                void *arg, int fd, struct iovec *bufs, size_t nbufs, off_t offset);
                    497: #endif /* EVFILT_LIO */
                    498: 
1.10      misho     499: /*
                    500:  * schedUser() - Add trigger USER task to scheduler queue
                    501:  *
                    502:  * @root = root task
                    503:  * @func = task execution function
                    504:  * @arg = 1st func argument
                    505:  * @id = Trigger ID
                    506:  * @opt_data = Optional data
                    507:  * @opt_dlen = Optional user's trigger flags
                    508:  * return: NULL error or !=NULL new queued task
                    509:  */
                    510: sched_task_t *schedUser(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    511:                unsigned long id, void *opt_data, size_t opt_dlen);
                    512: #define schedUserSelf(x)       schedUser(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    513:                TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
                    514: /*
                    515:  * schedTrigger() - Triggering USER task
                    516:  *
                    517:  * @task = task
                    518:  * return: -1 error or 0 ok
                    519:  */
                    520: int schedTrigger(sched_task_t * __restrict task);
                    521: 
                    522: /*
1.1       misho     523:  * schedTimer() - Add TIMER task to scheduler queue
1.6       misho     524:  *
1.1       misho     525:  * @root = root task
                    526:  * @func = task execution function
                    527:  * @arg = 1st func argument
1.5       misho     528:  * @ts = timeout argument structure
                    529:  * @opt_data = Optional data
                    530:  * @opt_dlen = Optional data length
1.1       misho     531:  * return: NULL error or !=NULL new queued task
                    532:  */
1.5       misho     533: sched_task_t *schedTimer(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    534:                struct timespec ts, void *opt_data, size_t opt_dlen);
1.8       misho     535: #define schedTimerSelf(x)      schedTimer(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    536:                TASK_TS((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.1       misho     537: /*
                    538:  * schedEvent() - Add EVENT task to scheduler queue
1.6       misho     539:  *
1.1       misho     540:  * @root = root task
                    541:  * @func = task execution function
                    542:  * @arg = 1st func argument
1.2       misho     543:  * @val = additional func argument
1.5       misho     544:  * @opt_data = Optional data
                    545:  * @opt_dlen = Optional data length
1.1       misho     546:  * return: NULL error or !=NULL new queued task
                    547:  */
1.5       misho     548: sched_task_t *schedEvent(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    549:                unsigned long val, void *opt_data, size_t opt_dlen);
1.8       misho     550: #define schedEventSelf(x)      schedEvent(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    551:                TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.1       misho     552: /*
1.13      misho     553:  * schedTask() - Add regular task to scheduler queue
1.6       misho     554:  *
1.1       misho     555:  * @root = root task
                    556:  * @func = task execution function
                    557:  * @arg = 1st func argument
1.13      misho     558:  * @prio = regular task priority, 0 is hi priority for regular tasks
1.5       misho     559:  * @opt_data = Optional data
                    560:  * @opt_dlen = Optional data length
1.1       misho     561:  * return: NULL error or !=NULL new queued task
                    562:  */
1.13      misho     563: sched_task_t *schedTask(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    564:                unsigned long prio, void *opt_data, size_t opt_dlen);
                    565: #define schedTaskSelf(x)       schedTask(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
1.8       misho     566:                TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.11      misho     567: /*
                    568:  * schedSuspend() - Add Suspended task to scheduler queue
                    569:  *
                    570:  * @root = root task
                    571:  * @func = task execution function
                    572:  * @arg = 1st func argument
                    573:  * @id = Trigger ID
                    574:  * @opt_data = Optional data
                    575:  * @opt_dlen = Optional user's trigger flags
                    576:  * return: NULL error or !=NULL new queued task
                    577:  */
                    578: sched_task_t *schedSuspend(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    579:                unsigned long id, void *opt_data, size_t opt_dlen);
                    580: #define schedSuspendSelf(x)    schedUser(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    581:                TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
                    582: /*
                    583:  * schedResumeby() - Resume suspended task
                    584:  *
                    585:  * @root = root task
                    586:  * @criteria = find task by criteria 
                    587:  *     [CRITERIA_ANY|CRITERIA_ID|CRITERIA_DATA]
                    588:  * @param = search parameter (sched_task_t *task| u_long id)
                    589:  * return: -1 error or 0 resumed ok
                    590:  */
                    591: int schedResumeby(sched_root_task_t * __restrict root, unsigned char criteria, void *param);
1.10      misho     592: 
1.1       misho     593: /*
                    594:  * schedCallOnce() - Call once from scheduler
1.6       misho     595:  *
1.1       misho     596:  * @root = root task
                    597:  * @func = task execution function
                    598:  * @arg = 1st func argument
1.2       misho     599:  * @val = additional func argument
1.5       misho     600:  * @opt_data = Optional data
                    601:  * @opt_dlen = Optional data length
1.2       misho     602:  * return: return value from called func
1.1       misho     603:  */
1.5       misho     604: sched_task_t *schedCallOnce(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    605:                unsigned long val, void *opt_data, size_t opt_dlen);
1.8       misho     606: #define schedCallAgain(x)      schedCallOnce(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    607:                TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.1       misho     608: 
                    609: 
                    610: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>