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

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