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