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