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