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