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