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