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