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