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

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