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

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.11.2.6! misho       6: * $Id: aitsched.h,v 1.11.2.5 2012/08/01 15:17:38 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.11.2.5  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.11.2.3  misho      56: #ifdef EVFILT_AIO
                     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,
                     83:        taskSIGNAL,
1.11.2.2  misho      84:        taskAIO,
                     85:        taskUSER,
1.9       misho      86:        taskEVENT,
                     87:        taskEVENTLO,
1.11      misho      88:        taskSUSPEND, 
1.1       misho      89:        taskREADY,
                     90:        taskUNUSE,
                     91:        taskMAX
                     92: } sched_task_type_t;
                     93: 
                     94: /* hooks */
                     95: typedef void *(*sched_hook_func_t)(void *, void *);
                     96: struct sched_HooksTask {
                     97:        struct {
                     98:                /* read(sched_task_t *task, NULL) -> int */
                     99:                sched_hook_func_t       read;
                    100:                /* write(sched_task_t *task, NULL) -> int */
                    101:                sched_hook_func_t       write;
1.10      misho     102:                /* timer(sched_task_t *task, struct timespec *ts) -> int */
                    103:                sched_hook_func_t       timer;
                    104:                /* alarm(sched_task_t *task, NULL) -> int */
                    105:                sched_hook_func_t       alarm;
                    106:                /* node(sched_task_t *task, NULL) -> int */
                    107:                sched_hook_func_t       node;
                    108:                /* proc(sched_task_t *task, NULL) -> int */
                    109:                sched_hook_func_t       proc;
                    110:                /* signal(sched_task_t *task, NULL) -> int */
                    111:                sched_hook_func_t       signal;
1.11.2.2  misho     112:                /* aio(sched_task_t *task, NULL) -> int */
                    113:                sched_hook_func_t       aio;
                    114:                /* user(sched_task_t *task, NULL) -> int */
                    115:                sched_hook_func_t       user;
1.1       misho     116:                /* event(sched_task_t *task, NULL) -> int */
                    117:                sched_hook_func_t       event;
                    118:                /* eventlo(sched_task_t *task, NULL) -> int */
                    119:                sched_hook_func_t       eventlo;
1.11      misho     120:                /* suspend(sched_task_t *task, NULL) -> int */
                    121:                sched_hook_func_t       suspend;
1.1       misho     122:        }       hook_add;
                    123:        struct {
                    124:                /* cancel(sched_task_t *task, NULL) -> int */
                    125:                sched_hook_func_t       cancel;
1.11      misho     126:                /* resume(sched_task_t *task, NULL) -> int */
                    127:                sched_hook_func_t       resume;
1.1       misho     128:                /* run(sched_root_task_t *root, NULL) -> int */
                    129:                sched_hook_func_t       run;
                    130:                /* fetch(sched_root_task_t *root, NULL) -> sched_task_t* */
                    131:                sched_hook_func_t       fetch;
1.3       misho     132:                /* exception(sched_root_task_t *root, NULL) -> int */
                    133:                sched_hook_func_t       exception;
1.6       misho     134:                /* condition(sched_root_task_t *root, intptr_t *stopValue) -> int */
                    135:                sched_hook_func_t       condition;
1.1       misho     136:        }       hook_exec;
                    137:        struct {
                    138:                /* init(sched_root_task_t *root, void *data) -> int */
                    139:                sched_hook_func_t       init;
                    140:                /* fini(sched_root_task_t *root, NULL) -> int */
                    141:                sched_hook_func_t       fini;
1.3       misho     142:                /* error(sched_root_task_t *root, int errno) -> int */
                    143:                sched_hook_func_t       error;
1.1       misho     144:        }       hook_root;
                    145: };
                    146: typedef struct sched_HooksTask hooks_task_t;
                    147: 
                    148: /* task callback, like pthread callback! */
1.2       misho     149: typedef void *(*sched_task_func_t)(sched_task_t * /* current task data*/);
1.1       misho     150: 
1.4       misho     151: /* task lock helpers */
1.10      misho     152: #define TASK_LOCK(x)           ((x)->task_lock = 42)
1.4       misho     153: #define TASK_UNLOCK(x)         ((x)->task_lock ^= (x)->task_lock)
                    154: #define TASK_ISLOCKED(x)       ((x)->task_lock)
                    155: 
1.1       misho     156: /* task & queue */
                    157: struct sched_Task {
1.4       misho     158:        volatile int                    task_lock;
1.10      misho     159:        uintptr_t                       task_id;
                    160: #define TASK_ID(x)     ((struct sched_Task*) (x)->task_id)
1.1       misho     161:        sched_task_type_t               task_type;
1.5       misho     162: #define TASK_TYPE(x)   (x)->task_type
1.1       misho     163: 
                    164:        sched_root_task_t               *task_root;
1.2       misho     165: #define TASK_ROOT(x)   (x)->task_root
1.1       misho     166:        sched_task_func_t               task_func;
1.8       misho     167: #define TASK_FUNC(x)   (x)->task_func
1.1       misho     168: 
                    169:        void                            *task_arg;
                    170:        union {
                    171:                unsigned long   v;
1.3       misho     172:                intptr_t        fd;
1.5       misho     173:                struct timespec ts;
1.1       misho     174:        }                               task_val;
                    175: #define TASK_ARG(x)    (x)->task_arg
                    176: #define TASK_VAL(x)    (x)->task_val.v
                    177: #define TASK_FD(x)     (x)->task_val.fd
1.5       misho     178: #define TASK_TS(x)     (x)->task_val.ts
1.1       misho     179: 
                    180:        struct iovec                    task_data;
                    181: #define TASK_DATA(x)   (x)->task_data.iov_base
                    182: #define TASK_DATLEN(x) (x)->task_data.iov_len
                    183: 
                    184:        TAILQ_ENTRY(sched_Task)         task_node;
                    185: };
                    186: typedef TAILQ_HEAD(, sched_Task) sched_queue_t;
1.5       misho     187: #define TASK_DATA_SET(x, _dp, _dl)     do { \
                    188:                                                if ((x)) { \
                    189:                                                        (x)->task_data.iov_base = (_dp); \
                    190:                                                        (x)->task_data.iov_len = _dl; \
                    191:                                                } \
                    192:                                        while (0)
1.1       misho     193: 
                    194: /* root task */
                    195: struct sched_RootTask {
                    196:        int             root_kq;
1.5       misho     197:        struct timespec root_wait;
                    198:        struct timespec root_poll;
1.6       misho     199:        intptr_t        root_cond;
1.11.2.1  misho     200:        void            *root_ret;
1.6       misho     201: 
1.5       misho     202:        pthread_mutex_t root_mtx[taskMAX];
1.1       misho     203: 
                    204:        sched_queue_t   root_read;
                    205:        sched_queue_t   root_write;
                    206:        sched_queue_t   root_timer;
1.9       misho     207:        sched_queue_t   root_alarm;
1.10      misho     208:        sched_queue_t   root_node;
                    209:        sched_queue_t   root_proc;
                    210:        sched_queue_t   root_signal;
1.11.2.2  misho     211:        sched_queue_t   root_aio;
                    212:        sched_queue_t   root_user;
1.1       misho     213:        sched_queue_t   root_event;
1.10      misho     214:        sched_queue_t   root_eventlo;
1.11      misho     215:        sched_queue_t   root_suspend;
1.1       misho     216:        sched_queue_t   root_ready;
                    217:        sched_queue_t   root_unuse;
                    218:        int             root_eventlo_miss;
                    219: 
                    220:        hooks_task_t    root_hooks;
                    221:        struct iovec    root_data;
                    222: #define ROOT_DATA(x)   (x)->root_data.iov_base
                    223: #define ROOT_DATLEN(x) (x)->root_data.iov_len
                    224: };
1.7       misho     225: #define ROOT_QUEUE_EMPTY(x, _q)        TAILQ_EMPTY(&((x)->root_##_q))
1.11.2.1  misho     226: #define ROOT_RETURN(x) (x)->root_ret
1.1       misho     227: 
                    228: 
1.2       misho     229: inline int sched_GetErrno();
                    230: inline const char *sched_GetError();
                    231: 
                    232: 
1.1       misho     233: /*
                    234:  * schedInit() - Init scheduler
1.6       misho     235:  *
1.1       misho     236:  * @data = optional data if !=NULL
                    237:  * @datlen = data len if data is set
                    238:  * return: allocated root task if ok or NULL error
                    239:  */
                    240: sched_root_task_t *schedInit(void ** __restrict data, size_t datlen);
1.2       misho     241: #define schedBegin()   schedInit((void**) &schedRegisterHooks, 0)
1.1       misho     242: /*
                    243:  * schedEnd() - End scheduler & free all resources
1.6       misho     244:  *
1.1       misho     245:  * @root = root task
                    246:  * return: -1 error or 0 ok
                    247:  */
1.2       misho     248: int schedEnd(sched_root_task_t ** __restrict root);
1.1       misho     249: /*
1.2       misho     250:  * schedRegisterHooks() - Register IO handles and bind tasks to it
1.6       misho     251:  *
1.1       misho     252:  * @root = root task
                    253:  * return: -1 error or 0 ok
                    254:  */
1.2       misho     255: int schedRegisterHooks(sched_root_task_t * __restrict root);
1.1       misho     256: /*
1.5       misho     257:  * schedPolling() - Polling timeout period if no timer task is present
1.6       misho     258:  *
1.5       misho     259:  * @root = root task
                    260:  * @ts = timeout polling period, if ==NULL INFINIT timeout
                    261:  * @tsold = old timeout polling if !=NULL
                    262:  * return: -1 error or 0 ok
                    263:  */
                    264: inline int schedPolling(sched_root_task_t * __restrict root, 
                    265:                struct timespec * __restrict ts, struct timespec * __restrict tsold);
                    266: /*
1.6       misho     267:  * schedTermCondition() - Activate hook for scheduler condition kill
                    268:  *
                    269:  * @root = root task
                    270:  * @condValue = condition value, kill schedRun() if condValue == killState
                    271:  * return: -1 error ok 0 ok
                    272:  */
                    273: inline int schedTermCondition(sched_root_task_t * __restrict root, intptr_t condValue);
                    274: /*
1.1       misho     275:  * schedCall() - Call task execution function
1.6       misho     276:  *
1.1       misho     277:  * @task = current task
                    278:  * return: !=NULL error or =NULL ok
                    279:  */
                    280: inline void *schedCall(sched_task_t * __restrict task);
                    281: /*
                    282:  * schedFetch() - Fetch ready task
1.6       misho     283:  *
1.1       misho     284:  * @root = root task
                    285:  * return: =NULL error or !=NULL ready task
                    286:  */
                    287: inline void *schedFetch(sched_root_task_t * __restrict root);
                    288: /*
                    289:  * schedRun() - Scheduler *run loop*
1.6       misho     290:  *
1.1       misho     291:  * @root = root task
1.2       misho     292:  * @killState = kill condition variable, if !=0 stop scheduler loop
1.1       misho     293:  * return: -1 error or 0 ok
                    294:  */
1.7       misho     295: int schedRun(sched_root_task_t *root, volatile intptr_t * __restrict killState);
1.1       misho     296: /*
                    297:  * schedCancel() - Cancel task from scheduler
1.6       misho     298:  *
1.1       misho     299:  * @task = task
                    300:  * return: -1 error or 0 ok
                    301:  */
                    302: int schedCancel(sched_task_t * __restrict task);
                    303: /*
                    304:  * schedCancelby() - Cancel task from scheduler by criteria
1.6       misho     305:  *
1.1       misho     306:  * @root = root task
1.5       misho     307:  * @type = cancel from queue type, if =taskMAX cancel same task from all queues
1.10      misho     308:  * @criteria = find task by criteria 
1.11      misho     309:  *     [CRITERIA_ANY|CRITERIA_CALL|CRITERIA_ARG|CRITERIA_FD|CRITERIA_VAL|CRITERIA_ID|CRITERIA_TS|CRITERIA_DATA]
1.1       misho     310:  * @param = search parameter
                    311:  * @hook = custom cleanup hook function, may be NULL
1.3       misho     312:  * return: -1 error, -2 error in sub-stage cancel execution, -3 error from custom hook or 0 ok
1.1       misho     313:  */
1.5       misho     314: int schedCancelby(sched_root_task_t * __restrict root, sched_task_type_t type, 
1.1       misho     315:                u_char criteria, void *param, sched_hook_func_t hook);
                    316: 
                    317: 
                    318: /*
1.2       misho     319:  * schedRead() - Add READ I/O task to scheduler queue
1.6       misho     320:  *
1.1       misho     321:  * @root = root task
                    322:  * @func = task execution function
                    323:  * @arg = 1st func argument
1.2       misho     324:  * @fd = fd handle
1.5       misho     325:  * @opt_data = Optional data
                    326:  * @opt_dlen = Optional data length
1.1       misho     327:  * return: NULL error or !=NULL new queued task
                    328:  */
1.5       misho     329: sched_task_t *schedRead(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    330:                int fd, void *opt_data, size_t opt_dlen);
1.8       misho     331: #define schedReadSelf(x)       schedRead(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    332:                TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.1       misho     333: /*
1.2       misho     334:  * schedWrite() - Add WRITE I/O task to scheduler queue
1.6       misho     335:  *
1.1       misho     336:  * @root = root task
                    337:  * @func = task execution function
                    338:  * @arg = 1st func argument
1.2       misho     339:  * @fd = fd handle
1.5       misho     340:  * @opt_data = Optional data
                    341:  * @opt_dlen = Optional data length
1.1       misho     342:  * return: NULL error or !=NULL new queued task
                    343:  */
1.5       misho     344: sched_task_t *schedWrite(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    345:                int fd, void *opt_data, size_t opt_dlen);
1.8       misho     346: #define schedWriteSelf(x)      schedWrite(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    347:                TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.1       misho     348: /*
1.9       misho     349:  * schedAlarm() - Add ALARM task to scheduler queue
                    350:  *
                    351:  * @root = root task
                    352:  * @func = task execution function
                    353:  * @arg = 1st func argument
                    354:  * @ts = timeout argument structure, minimum alarm timer resolution is 1msec!
                    355:  * @opt_data = Optional data
                    356:  * @opt_dlen = Optional data length
                    357:  * return: NULL error or !=NULL new queued task
                    358:  */
                    359: sched_task_t *schedAlarm(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    360:                struct timespec ts, void *opt_data, size_t opt_dlen);
                    361: #define schedAlarmSelf(x)      schedAlarm(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    362:                TASK_TS((x)), TASK_DATA((x)), TASK_DATLEN((x)))
                    363: /*
1.10      misho     364:  * schedNode() - Add NODE task to scheduler queue
                    365:  *
                    366:  * @root = root task
                    367:  * @func = task execution function
                    368:  * @arg = 1st func argument
                    369:  * @fd = fd handle
                    370:  * @opt_data = Optional data
                    371:  * @opt_dlen = Optional data length
                    372:  * return: NULL error or !=NULL new queued task
                    373:  */
                    374: sched_task_t *schedNode(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    375:                int fd, void *opt_data, size_t opt_dlen);
                    376: #define schedNodeSelf(x)       schedNode(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    377:                TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
                    378: /*
                    379:  * schedProc() - Add PROC task to scheduler queue
                    380:  *
                    381:  * @root = root task
                    382:  * @func = task execution function
                    383:  * @arg = 1st func argument
                    384:  * @pid = PID
                    385:  * @opt_data = Optional data
                    386:  * @opt_dlen = Optional data length
                    387:  * return: NULL error or !=NULL new queued task
                    388:  */
                    389: sched_task_t *schedProc(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    390:                unsigned long pid, void *opt_data, size_t opt_dlen);
                    391: #define schedProcSelf(x)       schedProc(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    392:                TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
                    393: /*
                    394:  * schedSignal() - Add SIGNAL task to scheduler queue
                    395:  *
                    396:  * @root = root task
                    397:  * @func = task execution function
                    398:  * @arg = 1st func argument
                    399:  * @sig = Signal
                    400:  * @opt_data = Optional data
                    401:  * @opt_dlen = Optional data length
                    402:  * return: NULL error or !=NULL new queued task
                    403:  */
                    404: sched_task_t *schedSignal(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    405:                unsigned long sig, void *opt_data, size_t opt_dlen);
                    406: #define schedSignalSelf(x)     schedSignal(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    407:                TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
                    408: 
1.11.2.6! misho     409: #ifdef EVFILT_AIO
1.10      misho     410: /*
1.11.2.2  misho     411:  * schedAIO() - Add AIO task to scheduler queue
                    412:  *
                    413:  * @root = root task
                    414:  * @func = task execution function
                    415:  * @arg = 1st func argument
                    416:  * @acb = AIO cb structure address
                    417:  * @opt_data = Optional data
                    418:  * @opt_dlen = Optional data length
                    419:  * return: NULL error or !=NULL new queued task
                    420:  */
                    421: sched_task_t *schedAIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
1.11.2.3  misho     422:                struct aiocb * __restrict acb, void *opt_data, size_t opt_dlen);
                    423: /*
                    424:  * schedAIORead() - Add AIO read task to scheduler queue
                    425:  *
                    426:  * @root = root task
                    427:  * @func = task execution function
                    428:  * @arg = 1st func argument
                    429:  * @fd = file descriptor
                    430:  * @buffer = Buffer
                    431:  * @buflen = Buffer length
                    432:  * return: NULL error or !=NULL new queued task
                    433:  */
                    434: inline sched_task_t *schedAIORead(sched_root_task_t * __restrict root, sched_task_func_t func, 
                    435:                void *arg, int fd, void *buffer, size_t buflen);
                    436: /*
                    437:  * schedAIOWrite() - Add AIO write task to scheduler queue
                    438:  *
                    439:  * @root = root task
                    440:  * @func = task execution function
                    441:  * @arg = 1st func argument
                    442:  * @fd = file descriptor
                    443:  * @buffer = Buffer
                    444:  * @buflen = Buffer length
                    445:  * return: NULL error or !=NULL new queued task
                    446:  */
                    447: inline sched_task_t *schedAIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func, 
                    448:                void *arg, int fd, void *buffer, size_t buflen);
1.11.2.6! misho     449: #ifdef EVFILT_LIO
        !           450: /*
        !           451:  * schedLIORead() - Add list of AIO read tasks to scheduler queue
        !           452:  *
        !           453:  * @root = root task
        !           454:  * @func = task execution function
        !           455:  * @arg = 1st func argument
        !           456:  * @fd = file descriptor
        !           457:  * @bufs = Buffer's list
        !           458:  * @nbufs = Number of Buffers
        !           459:  * return: NULL error or !=NULL new queued task
        !           460:  */
        !           461: inline sched_task_t *schedLIORead(sched_root_task_t * __restrict root, sched_task_func_t func, 
        !           462:                void *arg, int fd, struct iovec *bufs, size_t nbufs);
        !           463: /*
        !           464:  * schedLIOWrite() - Add list of AIO write tasks to scheduler queue
        !           465:  *
        !           466:  * @root = root task
        !           467:  * @func = task execution function
        !           468:  * @arg = 1st func argument
        !           469:  * @fd = file descriptor
        !           470:  * @bufs = Buffer's list
        !           471:  * @nbufs = Number of Buffers
        !           472:  * return: NULL error or !=NULL new queued task
        !           473:  */
        !           474: inline sched_task_t *schedLIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func, 
        !           475:                void *arg, int fd, struct iovec *bufs, size_t nbufs);
        !           476: #endif /* EVFILT_LIO */
        !           477: #endif /* EVFILT_AIO */
1.11.2.2  misho     478: 
                    479: /*
1.10      misho     480:  * schedUser() - Add trigger USER task to scheduler queue
                    481:  *
                    482:  * @root = root task
                    483:  * @func = task execution function
                    484:  * @arg = 1st func argument
                    485:  * @id = Trigger ID
                    486:  * @opt_data = Optional data
                    487:  * @opt_dlen = Optional user's trigger flags
                    488:  * return: NULL error or !=NULL new queued task
                    489:  */
                    490: sched_task_t *schedUser(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    491:                unsigned long id, void *opt_data, size_t opt_dlen);
                    492: #define schedUserSelf(x)       schedUser(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    493:                TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
                    494: /*
                    495:  * schedTrigger() - Triggering USER task
                    496:  *
                    497:  * @task = task
                    498:  * return: -1 error or 0 ok
                    499:  */
                    500: int schedTrigger(sched_task_t * __restrict task);
                    501: 
                    502: /*
1.1       misho     503:  * schedTimer() - Add TIMER task to scheduler queue
1.6       misho     504:  *
1.1       misho     505:  * @root = root task
                    506:  * @func = task execution function
                    507:  * @arg = 1st func argument
1.5       misho     508:  * @ts = timeout argument structure
                    509:  * @opt_data = Optional data
                    510:  * @opt_dlen = Optional data length
1.1       misho     511:  * return: NULL error or !=NULL new queued task
                    512:  */
1.5       misho     513: sched_task_t *schedTimer(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    514:                struct timespec ts, void *opt_data, size_t opt_dlen);
1.8       misho     515: #define schedTimerSelf(x)      schedTimer(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    516:                TASK_TS((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.1       misho     517: /*
                    518:  * schedEvent() - Add EVENT task to scheduler queue
1.6       misho     519:  *
1.1       misho     520:  * @root = root task
                    521:  * @func = task execution function
                    522:  * @arg = 1st func argument
1.2       misho     523:  * @val = additional func argument
1.5       misho     524:  * @opt_data = Optional data
                    525:  * @opt_dlen = Optional data length
1.1       misho     526:  * return: NULL error or !=NULL new queued task
                    527:  */
1.5       misho     528: sched_task_t *schedEvent(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    529:                unsigned long val, void *opt_data, size_t opt_dlen);
1.8       misho     530: #define schedEventSelf(x)      schedEvent(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    531:                TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.1       misho     532: /*
                    533:  * schedEventLo() - Add EVENT_Lo task to scheduler queue
1.6       misho     534:  *
1.1       misho     535:  * @root = root task
                    536:  * @func = task execution function
                    537:  * @arg = 1st func argument
1.2       misho     538:  * @val = additional func argument
1.5       misho     539:  * @opt_data = Optional data
                    540:  * @opt_dlen = Optional data length
1.1       misho     541:  * return: NULL error or !=NULL new queued task
                    542:  */
1.5       misho     543: sched_task_t *schedEventLo(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    544:                unsigned long val, void *opt_data, size_t opt_dlen);
1.8       misho     545: #define schedEventLoSelf(x)    schedEventLo(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    546:                TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.11      misho     547: /*
                    548:  * schedSuspend() - Add Suspended task to scheduler queue
                    549:  *
                    550:  * @root = root task
                    551:  * @func = task execution function
                    552:  * @arg = 1st func argument
                    553:  * @id = Trigger ID
                    554:  * @opt_data = Optional data
                    555:  * @opt_dlen = Optional user's trigger flags
                    556:  * return: NULL error or !=NULL new queued task
                    557:  */
                    558: sched_task_t *schedSuspend(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    559:                unsigned long id, void *opt_data, size_t opt_dlen);
                    560: #define schedSuspendSelf(x)    schedUser(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    561:                TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
                    562: /*
                    563:  * schedResumeby() - Resume suspended task
                    564:  *
                    565:  * @root = root task
                    566:  * @criteria = find task by criteria 
                    567:  *     [CRITERIA_ANY|CRITERIA_ID|CRITERIA_DATA]
                    568:  * @param = search parameter (sched_task_t *task| u_long id)
                    569:  * return: -1 error or 0 resumed ok
                    570:  */
                    571: int schedResumeby(sched_root_task_t * __restrict root, unsigned char criteria, void *param);
1.10      misho     572: 
1.1       misho     573: /*
                    574:  * schedCallOnce() - Call once from scheduler
1.6       misho     575:  *
1.1       misho     576:  * @root = root task
                    577:  * @func = task execution function
                    578:  * @arg = 1st func argument
1.2       misho     579:  * @val = additional func argument
1.5       misho     580:  * @opt_data = Optional data
                    581:  * @opt_dlen = Optional data length
1.2       misho     582:  * return: return value from called func
1.1       misho     583:  */
1.5       misho     584: sched_task_t *schedCallOnce(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
                    585:                unsigned long val, void *opt_data, size_t opt_dlen);
1.8       misho     586: #define schedCallAgain(x)      schedCallOnce(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
                    587:                TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.1       misho     588: 
                    589: 
                    590: #endif

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