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

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

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