Annotation of libaitsched/inc/aitsched.h, revision 1.14.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.14.2.2! misho 6: * $Id: aitsched.h,v 1.14.2.1 2012/08/21 11:07:16 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.6 misho 15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
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.12 misho 52: #include <sys/event.h>
1.2 misho 53: #include <sys/uio.h>
1.3 misho 54: #include <stdint.h>
1.5 misho 55: #include <pthread.h>
1.14.2.2! 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.11 misho 70: #define CRITERIA_ID 7
1.1 misho 71:
72:
73: /* early declaration for root & task */
74: typedef struct sched_Task sched_task_t;
75: typedef struct sched_RootTask sched_root_task_t;
76:
77: typedef enum {
78: taskREAD = 0,
79: taskWRITE,
80: taskTIMER,
1.10 misho 81: taskALARM,
82: taskNODE,
83: taskPROC,
1.12 misho 84: taskSIGNAL,
85: taskAIO,
86: taskLIO,
1.10 misho 87: taskUSER,
1.9 misho 88: taskEVENT,
1.13 misho 89: taskTASK,
1.11 misho 90: taskSUSPEND,
1.1 misho 91: taskREADY,
92: taskUNUSE,
1.14.2.1 misho 93: taskTHREAD,
1.1 misho 94: taskMAX
95: } sched_task_type_t;
96:
97: /* hooks */
98: typedef void *(*sched_hook_func_t)(void *, void *);
99: struct sched_HooksTask {
100: struct {
101: /* read(sched_task_t *task, NULL) -> int */
102: sched_hook_func_t read;
103: /* write(sched_task_t *task, NULL) -> int */
104: sched_hook_func_t write;
1.10 misho 105: /* timer(sched_task_t *task, struct timespec *ts) -> int */
106: sched_hook_func_t timer;
107: /* alarm(sched_task_t *task, NULL) -> int */
108: sched_hook_func_t alarm;
109: /* node(sched_task_t *task, NULL) -> int */
110: sched_hook_func_t node;
111: /* proc(sched_task_t *task, NULL) -> int */
112: sched_hook_func_t proc;
1.12 misho 113: /* signal(sched_task_t *task, NULL) -> int */
114: sched_hook_func_t signal;
115: /* aio(sched_task_t *task, NULL) -> int */
116: sched_hook_func_t aio;
117: /* lio(sched_task_t *task, NULL) -> int */
118: sched_hook_func_t lio;
1.10 misho 119: /* user(sched_task_t *task, NULL) -> int */
120: sched_hook_func_t user;
1.1 misho 121: /* event(sched_task_t *task, NULL) -> int */
122: sched_hook_func_t event;
1.13 misho 123: /* task(sched_task_t *task, NULL) -> int */
124: sched_hook_func_t task;
1.11 misho 125: /* suspend(sched_task_t *task, NULL) -> int */
126: sched_hook_func_t suspend;
1.14.2.1 misho 127: /* thread(sched_task_t *task, NULL) -> int */
128: sched_hook_func_t thread;
1.1 misho 129: } hook_add;
130: struct {
1.14.2.1 misho 131: /* exit(sched_task_t *task, void *exitValue) -> int */
132: sched_hook_func_t exit;
1.1 misho 133: /* cancel(sched_task_t *task, NULL) -> int */
134: sched_hook_func_t cancel;
1.11 misho 135: /* resume(sched_task_t *task, NULL) -> int */
136: sched_hook_func_t resume;
1.1 misho 137: /* run(sched_root_task_t *root, NULL) -> int */
138: sched_hook_func_t run;
139: /* fetch(sched_root_task_t *root, NULL) -> sched_task_t* */
140: sched_hook_func_t fetch;
1.3 misho 141: /* exception(sched_root_task_t *root, NULL) -> int */
142: sched_hook_func_t exception;
1.6 misho 143: /* condition(sched_root_task_t *root, intptr_t *stopValue) -> int */
144: sched_hook_func_t condition;
1.1 misho 145: } hook_exec;
146: struct {
147: /* init(sched_root_task_t *root, void *data) -> int */
148: sched_hook_func_t init;
149: /* fini(sched_root_task_t *root, NULL) -> int */
150: sched_hook_func_t fini;
1.3 misho 151: /* error(sched_root_task_t *root, int errno) -> int */
152: sched_hook_func_t error;
1.1 misho 153: } hook_root;
154: };
155: typedef struct sched_HooksTask hooks_task_t;
156:
157: /* task callback, like pthread callback! */
1.2 misho 158: typedef void *(*sched_task_func_t)(sched_task_t * /* current task data*/);
1.1 misho 159:
1.4 misho 160: /* task lock helpers */
1.10 misho 161: #define TASK_LOCK(x) ((x)->task_lock = 42)
1.4 misho 162: #define TASK_UNLOCK(x) ((x)->task_lock ^= (x)->task_lock)
163: #define TASK_ISLOCKED(x) ((x)->task_lock)
164:
1.1 misho 165: /* task & queue */
166: struct sched_Task {
1.10 misho 167: uintptr_t task_id;
168: #define TASK_ID(x) ((struct sched_Task*) (x)->task_id)
1.1 misho 169: sched_task_type_t task_type;
1.5 misho 170: #define TASK_TYPE(x) (x)->task_type
1.14.2.1 misho 171: volatile int task_lock;
1.1 misho 172:
173: sched_root_task_t *task_root;
1.2 misho 174: #define TASK_ROOT(x) (x)->task_root
1.1 misho 175: sched_task_func_t task_func;
1.8 misho 176: #define TASK_FUNC(x) (x)->task_func
1.14.2.2! misho 177: intptr_t task_ret;
! 178: #define TASK_RET(x) (x)->task_ret
! 179: unsigned int task_flag;
! 180: #define TASK_FLAG(x) (x)->task_flag
1.1 misho 181:
182: void *task_arg;
183: union {
184: unsigned long v;
1.3 misho 185: intptr_t fd;
1.5 misho 186: struct timespec ts;
1.1 misho 187: } task_val;
188: #define TASK_ARG(x) (x)->task_arg
189: #define TASK_VAL(x) (x)->task_val.v
190: #define TASK_FD(x) (x)->task_val.fd
1.5 misho 191: #define TASK_TS(x) (x)->task_val.ts
1.1 misho 192:
193: struct iovec task_data;
194: #define TASK_DATA(x) (x)->task_data.iov_base
195: #define TASK_DATLEN(x) (x)->task_data.iov_len
196:
197: TAILQ_ENTRY(sched_Task) task_node;
198: };
199: typedef TAILQ_HEAD(, sched_Task) sched_queue_t;
1.5 misho 200: #define TASK_DATA_SET(x, _dp, _dl) do { \
201: if ((x)) { \
202: (x)->task_data.iov_base = (_dp); \
203: (x)->task_data.iov_len = _dl; \
204: } \
205: while (0)
1.1 misho 206:
207: /* root task */
208: struct sched_RootTask {
209: int root_kq;
1.14 misho 210: unsigned long root_miss;
1.5 misho 211: struct timespec root_wait;
212: struct timespec root_poll;
1.6 misho 213: intptr_t root_cond;
1.12 misho 214: void *root_ret;
1.6 misho 215:
1.5 misho 216: pthread_mutex_t root_mtx[taskMAX];
1.1 misho 217:
218: sched_queue_t root_read;
219: sched_queue_t root_write;
220: sched_queue_t root_timer;
1.9 misho 221: sched_queue_t root_alarm;
1.10 misho 222: sched_queue_t root_node;
223: sched_queue_t root_proc;
1.12 misho 224: sched_queue_t root_signal;
225: sched_queue_t root_aio;
226: sched_queue_t root_lio;
1.10 misho 227: sched_queue_t root_user;
1.1 misho 228: sched_queue_t root_event;
1.13 misho 229: sched_queue_t root_task;
1.11 misho 230: sched_queue_t root_suspend;
1.1 misho 231: sched_queue_t root_ready;
232: sched_queue_t root_unuse;
1.14.2.1 misho 233: sched_queue_t root_thread;
1.1 misho 234:
235: hooks_task_t root_hooks;
236: struct iovec root_data;
237: #define ROOT_DATA(x) (x)->root_data.iov_base
238: #define ROOT_DATLEN(x) (x)->root_data.iov_len
239: };
1.7 misho 240: #define ROOT_QUEUE_EMPTY(x, _q) TAILQ_EMPTY(&((x)->root_##_q))
1.12 misho 241: #define ROOT_RETURN(x) (x)->root_ret
1.1 misho 242:
243:
1.2 misho 244: inline int sched_GetErrno();
245: inline const char *sched_GetError();
246:
247:
1.1 misho 248: /*
249: * schedInit() - Init scheduler
1.6 misho 250: *
1.1 misho 251: * @data = optional data if !=NULL
252: * @datlen = data len if data is set
253: * return: allocated root task if ok or NULL error
254: */
255: sched_root_task_t *schedInit(void ** __restrict data, size_t datlen);
1.2 misho 256: #define schedBegin() schedInit((void**) &schedRegisterHooks, 0)
1.1 misho 257: /*
258: * schedEnd() - End scheduler & free all resources
1.6 misho 259: *
1.1 misho 260: * @root = root task
261: * return: -1 error or 0 ok
262: */
1.2 misho 263: int schedEnd(sched_root_task_t ** __restrict root);
1.1 misho 264: /*
1.2 misho 265: * schedRegisterHooks() - Register IO handles and bind tasks to it
1.6 misho 266: *
1.1 misho 267: * @root = root task
268: * return: -1 error or 0 ok
269: */
1.2 misho 270: int schedRegisterHooks(sched_root_task_t * __restrict root);
1.1 misho 271: /*
1.5 misho 272: * schedPolling() - Polling timeout period if no timer task is present
1.6 misho 273: *
1.5 misho 274: * @root = root task
275: * @ts = timeout polling period, if ==NULL INFINIT timeout
276: * @tsold = old timeout polling if !=NULL
277: * return: -1 error or 0 ok
278: */
279: inline int schedPolling(sched_root_task_t * __restrict root,
280: struct timespec * __restrict ts, struct timespec * __restrict tsold);
281: /*
1.6 misho 282: * schedTermCondition() - Activate hook for scheduler condition kill
283: *
284: * @root = root task
285: * @condValue = condition value, kill schedRun() if condValue == killState
1.13 misho 286: * return: -1 error or 0 ok
1.6 misho 287: */
288: inline int schedTermCondition(sched_root_task_t * __restrict root, intptr_t condValue);
289: /*
1.1 misho 290: * schedCall() - Call task execution function
1.6 misho 291: *
1.1 misho 292: * @task = current task
293: * return: !=NULL error or =NULL ok
294: */
295: inline void *schedCall(sched_task_t * __restrict task);
296: /*
297: * schedFetch() - Fetch ready task
1.6 misho 298: *
1.1 misho 299: * @root = root task
300: * return: =NULL error or !=NULL ready task
301: */
302: inline void *schedFetch(sched_root_task_t * __restrict root);
303: /*
304: * schedRun() - Scheduler *run loop*
1.6 misho 305: *
1.1 misho 306: * @root = root task
1.2 misho 307: * @killState = kill condition variable, if !=0 stop scheduler loop
1.1 misho 308: * return: -1 error or 0 ok
309: */
1.7 misho 310: int schedRun(sched_root_task_t *root, volatile intptr_t * __restrict killState);
1.1 misho 311: /*
312: * schedCancel() - Cancel task from scheduler
1.6 misho 313: *
1.1 misho 314: * @task = task
315: * return: -1 error or 0 ok
316: */
317: int schedCancel(sched_task_t * __restrict task);
318: /*
319: * schedCancelby() - Cancel task from scheduler by criteria
1.6 misho 320: *
1.1 misho 321: * @root = root task
1.5 misho 322: * @type = cancel from queue type, if =taskMAX cancel same task from all queues
1.10 misho 323: * @criteria = find task by criteria
1.11 misho 324: * [CRITERIA_ANY|CRITERIA_CALL|CRITERIA_ARG|CRITERIA_FD|CRITERIA_VAL|CRITERIA_ID|CRITERIA_TS|CRITERIA_DATA]
1.1 misho 325: * @param = search parameter
326: * @hook = custom cleanup hook function, may be NULL
1.3 misho 327: * return: -1 error, -2 error in sub-stage cancel execution, -3 error from custom hook or 0 ok
1.1 misho 328: */
1.5 misho 329: int schedCancelby(sched_root_task_t * __restrict root, sched_task_type_t type,
1.1 misho 330: u_char criteria, void *param, sched_hook_func_t hook);
331:
332:
333: /*
1.2 misho 334: * schedRead() - Add READ I/O task to scheduler queue
1.6 misho 335: *
1.1 misho 336: * @root = root task
337: * @func = task execution function
338: * @arg = 1st func argument
1.2 misho 339: * @fd = fd handle
1.5 misho 340: * @opt_data = Optional data
341: * @opt_dlen = Optional data length
1.1 misho 342: * return: NULL error or !=NULL new queued task
343: */
1.5 misho 344: sched_task_t *schedRead(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg,
345: int fd, void *opt_data, size_t opt_dlen);
1.8 misho 346: #define schedReadSelf(x) schedRead(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
347: TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.1 misho 348: /*
1.2 misho 349: * schedWrite() - Add WRITE I/O task to scheduler queue
1.6 misho 350: *
1.1 misho 351: * @root = root task
352: * @func = task execution function
353: * @arg = 1st func argument
1.2 misho 354: * @fd = fd handle
1.5 misho 355: * @opt_data = Optional data
356: * @opt_dlen = Optional data length
1.1 misho 357: * return: NULL error or !=NULL new queued task
358: */
1.5 misho 359: sched_task_t *schedWrite(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg,
360: int fd, void *opt_data, size_t opt_dlen);
1.8 misho 361: #define schedWriteSelf(x) schedWrite(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
362: TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.1 misho 363: /*
1.9 misho 364: * schedAlarm() - Add ALARM task to scheduler queue
365: *
366: * @root = root task
367: * @func = task execution function
368: * @arg = 1st func argument
369: * @ts = timeout argument structure, minimum alarm timer resolution is 1msec!
370: * @opt_data = Optional data
371: * @opt_dlen = Optional data length
372: * return: NULL error or !=NULL new queued task
373: */
374: sched_task_t *schedAlarm(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg,
375: struct timespec ts, void *opt_data, size_t opt_dlen);
376: #define schedAlarmSelf(x) schedAlarm(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
377: TASK_TS((x)), TASK_DATA((x)), TASK_DATLEN((x)))
378: /*
1.10 misho 379: * schedNode() - Add NODE task to scheduler queue
380: *
381: * @root = root task
382: * @func = task execution function
383: * @arg = 1st func argument
384: * @fd = fd handle
385: * @opt_data = Optional data
386: * @opt_dlen = Optional data length
387: * return: NULL error or !=NULL new queued task
388: */
389: sched_task_t *schedNode(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg,
390: int fd, void *opt_data, size_t opt_dlen);
391: #define schedNodeSelf(x) schedNode(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
392: TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
393: /*
394: * schedProc() - Add PROC task to scheduler queue
395: *
396: * @root = root task
397: * @func = task execution function
398: * @arg = 1st func argument
399: * @pid = PID
400: * @opt_data = Optional data
401: * @opt_dlen = Optional data length
402: * return: NULL error or !=NULL new queued task
403: */
404: sched_task_t *schedProc(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg,
405: unsigned long pid, void *opt_data, size_t opt_dlen);
406: #define schedProcSelf(x) schedProc(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
407: TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
408: /*
409: * schedSignal() - Add SIGNAL task to scheduler queue
410: *
411: * @root = root task
412: * @func = task execution function
413: * @arg = 1st func argument
414: * @sig = Signal
415: * @opt_data = Optional data
416: * @opt_dlen = Optional data length
417: * return: NULL error or !=NULL new queued task
418: */
419: sched_task_t *schedSignal(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg,
420: unsigned long sig, void *opt_data, size_t opt_dlen);
421: #define schedSignalSelf(x) schedSignal(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
422: TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
423:
1.12 misho 424: #ifdef EVFILT_LIO
425: /*
426: * schedAIO() - Add AIO task to scheduler queue
427: *
428: * @root = root task
429: * @func = task execution function
430: * @arg = 1st func argument
431: * @acb = AIO cb structure address
432: * @opt_data = Optional data
433: * @opt_dlen = Optional data length
434: * return: NULL error or !=NULL new queued task
435: */
436: sched_task_t *schedAIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg,
437: struct aiocb * __restrict acb, void *opt_data, size_t opt_dlen);
438: /*
439: * schedAIORead() - Add AIO read task to scheduler queue
440: *
441: * @root = root task
442: * @func = task execution function
443: * @arg = 1st func argument
444: * @fd = file descriptor
445: * @buffer = Buffer
446: * @buflen = Buffer length
447: * @offset = Offset from start of file, if =-1 from current position
448: * return: NULL error or !=NULL new queued task
449: */
450: inline sched_task_t *schedAIORead(sched_root_task_t * __restrict root, sched_task_func_t func,
451: void *arg, int fd, void *buffer, size_t buflen, off_t offset);
452: /*
453: * schedAIOWrite() - Add AIO write task to scheduler queue
454: *
455: * @root = root task
456: * @func = task execution function
457: * @arg = 1st func argument
458: * @fd = file descriptor
459: * @buffer = Buffer
460: * @buflen = Buffer length
461: * @offset = Offset from start of file, if =-1 from current position
462: * return: NULL error or !=NULL new queued task
463: */
464: inline sched_task_t *schedAIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func,
465: void *arg, int fd, void *buffer, size_t buflen, off_t offset);
466:
467: /*
468: * schedLIO() - Add AIO bulk tasks to scheduler queue
469: *
470: * @root = root task
471: * @func = task execution function
472: * @arg = 1st func argument
473: * @acbs = AIO cb structure addresses
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 *schedLIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg,
479: struct aiocb ** __restrict acbs, void *opt_data, size_t opt_dlen);
480: /*
481: * schedLIORead() - Add list of AIO read tasks to scheduler queue
482: *
483: * @root = root task
484: * @func = task execution function
485: * @arg = 1st func argument
486: * @fd = file descriptor
487: * @bufs = Buffer's list
488: * @nbufs = Number of Buffers
489: * @offset = Offset from start of file, if =-1 from current position
490: * return: NULL error or !=NULL new queued task
491: */
492: inline sched_task_t *schedLIORead(sched_root_task_t * __restrict root, sched_task_func_t func,
493: void *arg, int fd, struct iovec *bufs, size_t nbufs, off_t offset);
494: /*
495: * schedLIOWrite() - Add list of AIO write tasks to scheduler queue
496: *
497: * @root = root task
498: * @func = task execution function
499: * @arg = 1st func argument
500: * @fd = file descriptor
501: * @bufs = Buffer's list
502: * @nbufs = Number of Buffers
503: * @offset = Offset from start of file, if =-1 from current position
504: * return: NULL error or !=NULL new queued task
505: */
506: inline sched_task_t *schedLIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func,
507: void *arg, int fd, struct iovec *bufs, size_t nbufs, off_t offset);
508: #endif /* EVFILT_LIO */
509:
1.10 misho 510: /*
511: * schedUser() - Add trigger USER task to scheduler queue
512: *
513: * @root = root task
514: * @func = task execution function
515: * @arg = 1st func argument
516: * @id = Trigger ID
517: * @opt_data = Optional data
518: * @opt_dlen = Optional user's trigger flags
519: * return: NULL error or !=NULL new queued task
520: */
521: sched_task_t *schedUser(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg,
522: unsigned long id, void *opt_data, size_t opt_dlen);
523: #define schedUserSelf(x) schedUser(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
524: TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
525: /*
526: * schedTrigger() - Triggering USER task
527: *
528: * @task = task
529: * return: -1 error or 0 ok
530: */
531: int schedTrigger(sched_task_t * __restrict task);
532:
533: /*
1.1 misho 534: * schedTimer() - Add TIMER task to scheduler queue
1.6 misho 535: *
1.1 misho 536: * @root = root task
537: * @func = task execution function
538: * @arg = 1st func argument
1.5 misho 539: * @ts = timeout argument structure
540: * @opt_data = Optional data
541: * @opt_dlen = Optional data length
1.1 misho 542: * return: NULL error or !=NULL new queued task
543: */
1.5 misho 544: sched_task_t *schedTimer(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg,
545: struct timespec ts, void *opt_data, size_t opt_dlen);
1.8 misho 546: #define schedTimerSelf(x) schedTimer(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
547: TASK_TS((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.1 misho 548: /*
549: * schedEvent() - Add EVENT task to scheduler queue
1.6 misho 550: *
1.1 misho 551: * @root = root task
552: * @func = task execution function
553: * @arg = 1st func argument
1.2 misho 554: * @val = additional func argument
1.5 misho 555: * @opt_data = Optional data
556: * @opt_dlen = Optional data length
1.1 misho 557: * return: NULL error or !=NULL new queued task
558: */
1.5 misho 559: sched_task_t *schedEvent(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg,
560: unsigned long val, void *opt_data, size_t opt_dlen);
1.8 misho 561: #define schedEventSelf(x) schedEvent(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
562: TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.1 misho 563: /*
1.13 misho 564: * schedTask() - Add regular task to scheduler queue
1.6 misho 565: *
1.1 misho 566: * @root = root task
567: * @func = task execution function
568: * @arg = 1st func argument
1.13 misho 569: * @prio = regular task priority, 0 is hi priority for regular tasks
1.5 misho 570: * @opt_data = Optional data
571: * @opt_dlen = Optional data length
1.1 misho 572: * return: NULL error or !=NULL new queued task
573: */
1.13 misho 574: sched_task_t *schedTask(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg,
575: unsigned long prio, void *opt_data, size_t opt_dlen);
576: #define schedTaskSelf(x) schedTask(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
1.8 misho 577: TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.11 misho 578: /*
579: * schedSuspend() - Add Suspended task to scheduler queue
580: *
581: * @root = root task
582: * @func = task execution function
583: * @arg = 1st func argument
584: * @id = Trigger ID
585: * @opt_data = Optional data
586: * @opt_dlen = Optional user's trigger flags
587: * return: NULL error or !=NULL new queued task
588: */
589: sched_task_t *schedSuspend(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg,
590: unsigned long id, void *opt_data, size_t opt_dlen);
591: #define schedSuspendSelf(x) schedUser(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
592: TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
593: /*
594: * schedResumeby() - Resume suspended task
595: *
596: * @root = root task
597: * @criteria = find task by criteria
598: * [CRITERIA_ANY|CRITERIA_ID|CRITERIA_DATA]
599: * @param = search parameter (sched_task_t *task| u_long id)
600: * return: -1 error or 0 resumed ok
601: */
602: int schedResumeby(sched_root_task_t * __restrict root, unsigned char criteria, void *param);
1.10 misho 603:
1.1 misho 604: /*
605: * schedCallOnce() - Call once from scheduler
1.6 misho 606: *
1.1 misho 607: * @root = root task
608: * @func = task execution function
609: * @arg = 1st func argument
1.2 misho 610: * @val = additional func argument
1.5 misho 611: * @opt_data = Optional data
612: * @opt_dlen = Optional data length
1.2 misho 613: * return: return value from called func
1.1 misho 614: */
1.5 misho 615: sched_task_t *schedCallOnce(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg,
616: unsigned long val, void *opt_data, size_t opt_dlen);
1.8 misho 617: #define schedCallAgain(x) schedCallOnce(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
618: TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
1.1 misho 619:
1.14.2.1 misho 620: /*
621: * schedThread() - Add thread task to scheduler queue
622: *
623: * @root = root task
624: * @func = task execution function
625: * @arg = 1st func argument
626: * @detach = Detach thread from scheduler, if !=0
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 *schedThread(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg,
632: int detach, void *opt_data, size_t opt_dlen);
633: #define schedThreadSelf(x) schedThread(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
634: TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
635: /*
636: * taskExit() - Exit routine for scheduler task
637: *
638: * @t = current executed task
639: * @x = exit value for task
640: * return: none
641: */
642: #define taskExit(t, x) do { assert((t) && TASK_ROOT(t)); \
643: if (TASK_ROOT(t)->root_hooks.hook_exec.exit) \
1.14.2.2! misho 644: TASK_ROOT(t)->root_hooks.hook_exec.exit((t), \
! 645: (void*) (x)); \
1.14.2.1 misho 646: TASK_ROOT(t)->root_ret = (void*) (x); \
647: if (TASK_TYPE(t) == taskTHREAD) \
648: pthread_exit((void*) (x)); \
649: else \
650: return ((void*) (x)); \
651: } while (0)
652:
1.1 misho 653:
654: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>