File:  [ELWIX - Embedded LightWeight unIX -] / libaitsched / inc / aitsched.h
Revision 1.30: download - view: text, annotated - select for diffs - revision graph
Tue Nov 29 20:15:18 2022 UTC (19 months ago) by misho
Branches: MAIN
CVS tags: sched7_3, sched7_2, SCHED7_2, SCHED7_1, HEAD
version 7.1

    1: /*************************************************************************
    2: * (C) 2011 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
    3: *  by Michael Pounov <misho@openbsd-bg.org>
    4: *
    5: * $Author: misho $
    6: * $Id: aitsched.h,v 1.30 2022/11/29 20:15:18 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 - 2022
   16: 	by Michael Pounov <misho@elwix.org>.  All rights reserved.
   17: 
   18: Redistribution and use in source and binary forms, with or without
   19: modification, are permitted provided that the following conditions
   20: are met:
   21: 1. Redistributions of source code must retain the above copyright
   22:    notice, this list of conditions and the following disclaimer.
   23: 2. Redistributions in binary form must reproduce the above copyright
   24:    notice, this list of conditions and the following disclaimer in the
   25:    documentation and/or other materials provided with the distribution.
   26: 3. All advertising materials mentioning features or use of this software
   27:    must display the following acknowledgement:
   28: This product includes software developed by Michael Pounov <misho@elwix.org>
   29: ELWIX - Embedded LightWeight unIX and its contributors.
   30: 4. Neither the name of AITNET nor the names of its contributors
   31:    may be used to endorse or promote products derived from this software
   32:    without specific prior written permission.
   33: 
   34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
   35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   37: ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   44: SUCH DAMAGE.
   45: */
   46: #ifndef __AITSCHED_H
   47: #define __AITSCHED_H
   48: 
   49: 
   50: #include <sys/types.h>
   51: #include <sys/queue.h>
   52: #include <sys/select.h>
   53: #include <sys/uio.h>
   54: #include <stdint.h>
   55: #include <pthread.h>
   56: #include <assert.h>
   57: #ifdef EVFILT_LIO
   58: #include <aio.h>
   59: #endif
   60: 
   61: 
   62: /* criteria type */
   63: #define CRITERIA_ANY	0
   64: #define CRITERIA_CALL	1
   65: #define CRITERIA_ARG	2
   66: #define CRITERIA_FD	3
   67: #define CRITERIA_VAL	4
   68: #define CRITERIA_TS	5
   69: #define CRITERIA_DATA	6
   70: #define CRITERIA_DATLEN	7
   71: #define CRITERIA_ID	8
   72: 
   73: 
   74: /* early declaration for root & task */
   75: typedef struct sched_Task	sched_task_t;
   76: typedef struct sched_RootTask	sched_root_task_t;
   77: 
   78: typedef enum {
   79: 	taskREAD = 0,
   80: 	taskWRITE,
   81: 	taskTIMER,
   82: 	taskALARM,
   83: 	taskNODE,
   84: 	taskPROC,
   85: 	taskSIGNAL,
   86: 	taskAIO,
   87: 	taskLIO,
   88: 	taskUSER,
   89: 	taskEVENT,
   90: 	taskTASK,
   91: 	taskSUSPEND, 
   92: 	taskREADY,
   93: 	taskUNUSE,
   94: 	taskTHREAD, 
   95: 	taskRTC,
   96: 	taskMAX
   97: } sched_task_type_t;
   98: 
   99: /* hooks */
  100: typedef void *(*sched_hook_func_t)(void *, void *);
  101: struct sched_HooksTask {
  102: 	struct {
  103: 		/* read(sched_task_t *task, NULL) -> int */
  104: 		sched_hook_func_t	read;
  105: 		/* write(sched_task_t *task, NULL) -> int */
  106: 		sched_hook_func_t	write;
  107: 		/* timer(sched_task_t *task, struct timespec *ts) -> int */
  108: 		sched_hook_func_t	timer;
  109: 		/* alarm(sched_task_t *task, NULL) -> int */
  110: 		sched_hook_func_t	alarm;
  111: 		/* node(sched_task_t *task, NULL) -> int */
  112: 		sched_hook_func_t	node;
  113: 		/* proc(sched_task_t *task, NULL) -> int */
  114: 		sched_hook_func_t	proc;
  115: 		/* signal(sched_task_t *task, NULL) -> int */
  116: 		sched_hook_func_t	signal;
  117: 		/* aio(sched_task_t *task, NULL) -> int */
  118: 		sched_hook_func_t	aio;
  119: 		/* lio(sched_task_t *task, NULL) -> int */
  120: 		sched_hook_func_t	lio;
  121: 		/* user(sched_task_t *task, NULL) -> int */
  122: 		sched_hook_func_t	user;
  123: 		/* event(sched_task_t *task, NULL) -> int */
  124: 		sched_hook_func_t	event;
  125: 		/* task(sched_task_t *task, NULL) -> int */
  126: 		sched_hook_func_t	task;
  127: 		/* suspend(sched_task_t *task, NULL) -> int */
  128: 		sched_hook_func_t	suspend;
  129: 		/* thread(sched_task_t *task, NULL) -> int */
  130: 		sched_hook_func_t	thread;
  131: 		/* rtc(sched_task_t *task, NULL) -> int */
  132: 		sched_hook_func_t	rtc;
  133: 	}	hook_add;
  134: 	struct {
  135: 		/* exit(sched_task_t *task, void *exitValue) -> int */
  136: 		sched_hook_func_t	exit;
  137: 		/* cancel(sched_task_t *task, NULL) -> int */
  138: 		sched_hook_func_t	cancel;
  139: 		/* resume(sched_task_t *task, NULL) -> int */
  140: 		sched_hook_func_t	resume;
  141: 		/* run(sched_root_task_t *root, NULL) -> int */
  142: 		sched_hook_func_t	run;
  143: 		/* fetch(sched_root_task_t *root, NULL) -> sched_task_t* */
  144: 		sched_hook_func_t	fetch;
  145: 		/* exception(sched_root_task_t *root, NULL) -> int */
  146: 		sched_hook_func_t	exception;
  147: 		/* condition(sched_root_task_t *root, intptr_t *stopValue) -> int */
  148: 		sched_hook_func_t	condition;
  149: 	}	hook_exec;
  150: 	struct {
  151: 		/* init(sched_root_task_t *root, void *data) -> int */
  152: 		sched_hook_func_t	init;
  153: 		/* fini(sched_root_task_t *root, NULL) -> int */
  154: 		sched_hook_func_t	fini;
  155: 		/* error(sched_root_task_t *root, int errno) -> int */
  156: 		sched_hook_func_t	error;
  157: 	}	hook_root;
  158: };
  159: typedef struct sched_HooksTask hooks_task_t;
  160: 
  161: /* task callback, like pthread callback! */
  162: typedef void *(*sched_task_func_t)(sched_task_t * /* current task data*/);
  163: #define SCHED_TASK_DEFINE(x)	void *(x)(sched_task_t*)
  164: 
  165: /* task lock helpers */
  166: #define TASK_LOCK(x)		((x)->task_lock = 42)
  167: #define TASK_UNLOCK(x)		((x)->task_lock ^= (x)->task_lock)
  168: #define TASK_ISLOCKED(x)	((x)->task_lock)
  169: 
  170: /* task & queue */
  171: struct sched_Task {
  172: 	uintptr_t			task_id;
  173: #define TASK_ID(x)	((struct sched_Task*) (x)->task_id)
  174: 	sched_task_type_t		task_type;
  175: #define TASK_TYPE(x)	(x)->task_type
  176: 	volatile int			task_lock;
  177: 
  178: 	sched_root_task_t		*task_root;
  179: #define TASK_ROOT(x)	(x)->task_root
  180: 	sched_task_func_t		task_func;
  181: #define TASK_FUNC(x)	(x)->task_func
  182: 	intptr_t			task_ret;
  183: #define TASK_RET(x)	(x)->task_ret
  184: 	unsigned long			task_flag;
  185: #define TASK_FLAG(x)	(x)->task_flag
  186: 
  187: 	void				*task_arg;
  188: 	union {
  189: 		unsigned long	v;
  190: 		intptr_t	fd;
  191: 		struct timespec	ts;
  192: 	}				task_val;
  193: #define TASK_ARG(x)	(x)->task_arg
  194: #define TASK_VAL(x)	(x)->task_val.v
  195: #define TASK_FD(x)	(x)->task_val.fd
  196: #define TASK_TS(x)	(x)->task_val.ts
  197: 
  198: #define TASK_TS2TV(x, tvp)	(assert((tvp)), (tvp)->tv_sec = (x)->task_val.ts.tv_sec, \
  199: 					(tvp)->tv_usec = (x)->task_val.ts.tv_nsec / 1000)
  200: 
  201: 	struct iovec			task_data;
  202: #define TASK_DATA(x)	(x)->task_data.iov_base
  203: #define TASK_DATLEN(x)	(x)->task_data.iov_len
  204: 
  205: 	unsigned long			task_harg;
  206: #define TASK_HARG(x)	(x)->task_harg
  207: 
  208: 	TAILQ_ENTRY(sched_Task)		task_node;
  209: };
  210: typedef TAILQ_HEAD(, sched_Task) sched_queue_t;
  211: #define TASK_DATA_SET(x, _dp, _dl)	do { \
  212: 						if ((x)) { \
  213: 							(x)->task_data.iov_base = (_dp); \
  214: 							(x)->task_data.iov_len = _dl; \
  215: 						} \
  216: 					while (0)
  217: 
  218: /* root task */
  219: struct sched_RootTask {
  220: 	int		root_kq;
  221: 	fd_set		root_fds[3];
  222: 	struct timespec	root_wait;
  223: 	struct timespec	root_poll;
  224: 	unsigned long	root_miss;
  225: 	intptr_t	root_cond[1];
  226: 	void		*root_ret;
  227: 
  228: 	pthread_mutex_t	root_mtx[taskMAX];
  229: 
  230: 	sched_queue_t	root_read;
  231: 	sched_queue_t	root_write;
  232: 	sched_queue_t	root_timer;
  233: 	sched_queue_t	root_alarm;
  234: 	sched_queue_t	root_node;
  235: 	sched_queue_t	root_proc;
  236: 	sched_queue_t	root_signal;
  237: 	sched_queue_t	root_aio;
  238: 	sched_queue_t	root_lio;
  239: 	sched_queue_t	root_user;
  240: 	sched_queue_t	root_event;
  241: 	sched_queue_t	root_task;
  242: 	sched_queue_t	root_suspend;
  243: 	sched_queue_t	root_ready;
  244: 	sched_queue_t	root_unuse;
  245: 	sched_queue_t	root_thread;
  246: 	sched_queue_t	root_rtc;
  247: 
  248: 	hooks_task_t	root_hooks;
  249: 	struct iovec	root_data;
  250: #define ROOT_DATA(x)	(x)->root_data.iov_base
  251: #define ROOT_DATLEN(x)	(x)->root_data.iov_len
  252: };
  253: #define ROOT_QUEUE_EMPTY(x, _q)	TAILQ_EMPTY(&((x)->root_##_q))
  254: #define ROOT_RETURN(x)	(x)->root_ret
  255: 
  256: 
  257: int sched_GetErrno();
  258: const char *sched_GetError();
  259: 
  260: 
  261: /*
  262:  * schedInit() - Init scheduler
  263:  *
  264:  * @data = optional data if !=NULL
  265:  * @datlen = data len if data is set
  266:  * return: allocated root task if ok or NULL error
  267:  */
  268: sched_root_task_t *schedInit(void ** __restrict data, size_t datlen);
  269: #define schedBegin()	schedInit((void**) &schedRegisterHooks, 0)
  270: /*
  271:  * schedEnd() - End scheduler & free all resources
  272:  *
  273:  * @root = root task
  274:  * return: -1 error or 0 ok
  275:  */
  276: int schedEnd(sched_root_task_t ** __restrict root);
  277: /*
  278:  * schedRegisterHooks() - Register IO handles and bind tasks to it
  279:  *
  280:  * @root = root task
  281:  * return: -1 error or 0 ok
  282:  */
  283: int schedRegisterHooks(sched_root_task_t * __restrict root);
  284: /*
  285:  * sched_useTask() - Get and init new task
  286:  *
  287:  * @root = root task
  288:  * return: NULL error or !=NULL prepared task
  289:  */
  290: sched_task_t *sched_useTask(sched_root_task_t * __restrict root);
  291: /*
  292:  * sched_unuseTask() - Unlock and put task to unuse queue
  293:  *
  294:  * @task = task
  295:  * return: always is NULL
  296:  */
  297: sched_task_t *sched_unuseTask(sched_task_t * __restrict task);
  298: /*
  299:  * schedPolling() - Polling timeout period if no timer task is present
  300:  *
  301:  * @root = root task
  302:  * @ts = timeout polling period, if ==NULL INFINIT timeout
  303:  * @tsold = old timeout polling if !=NULL
  304:  * return: -1 error or 0 ok
  305:  */
  306: int schedPolling(sched_root_task_t * __restrict root, 
  307: 		struct timespec * __restrict ts, struct timespec * __restrict tsold);
  308: /*
  309:  * schedTermCondition() - Activate hook for scheduler condition kill
  310:  *
  311:  * @root = root task
  312:  * @condValue = condition value, kill schedRun() if condValue == killState
  313:  * return: -1 error or 0 ok
  314:  */
  315: int schedTermCondition(sched_root_task_t * __restrict root, intptr_t * __restrict condValue);
  316: /*
  317:  * schedCall() - Call task execution function
  318:  *
  319:  * @task = current task
  320:  * return: !=NULL error or =NULL ok
  321:  */
  322: void *schedCall(sched_task_t * __restrict task);
  323: /*
  324:  * schedFetch() - Fetch ready task
  325:  *
  326:  * @root = root task
  327:  * return: =NULL error or !=NULL ready task
  328:  */
  329: void *schedFetch(sched_root_task_t * __restrict root);
  330: /*
  331:  * schedRun() - Scheduler *run loop*
  332:  *
  333:  * @root = root task
  334:  * @killState = kill condition variable, if !=0 stop scheduler loop
  335:  * return: -1 error or 0 ok
  336:  */
  337: int schedRun(sched_root_task_t *root, volatile intptr_t * __restrict killState);
  338: /*
  339:  * schedCancel() - Cancel task from scheduler
  340:  *
  341:  * @task = task
  342:  * return: -1 error or 0 ok
  343:  */
  344: int schedCancel(sched_task_t * __restrict task);
  345: /*
  346:  * schedCancelby() - Cancel task from scheduler by criteria
  347:  *
  348:  * @root = root task
  349:  * @type = cancel from queue type, if =taskMAX cancel same task from all queues
  350:  * @criteria = find task by criteria 
  351:  * 	[ CRITERIA_ANY|CRITERIA_CALL|CRITERIA_ARG|CRITERIA_FD|CRITERIA_VAL|
  352:  * 		CRITERIA_ID|CRITERIA_TS|CRITERIA_DATA|CRITERIA_DATLEN ]
  353:  * @param = search parameter
  354:  * @hook = custom cleanup hook function, may be NULL
  355:  * return: -1 error, -2 error in sub-stage cancel execution, -3 error from custom hook or 0 ok
  356:  */
  357: int schedCancelby(sched_root_task_t * __restrict root, sched_task_type_t type, 
  358: 		unsigned char criteria, void *param, sched_hook_func_t hook);
  359: /*
  360:  * schedQuery() - Query task in scheduler
  361:  *
  362:  * @task = task
  363:  * return: -1 error, 0 found  and 1 not found
  364:  */
  365: int schedQuery(sched_task_t * __restrict task);
  366: /*
  367:  * schedQueryby() - Query task in scheduler by criteria
  368:  *
  369:  * @root = root task
  370:  * @type = query from queue type, if =taskMAX query same task from all queues
  371:  * @criteria = find task by criteria 
  372:  * 	[ CRITERIA_ANY|CRITERIA_CALL|CRITERIA_ARG|CRITERIA_FD|CRITERIA_VAL|
  373:  * 		CRITERIA_ID|CRITERIA_TS|CRITERIA_DATA|CRITERIA_DATLEN ]
  374:  * @param = search parameter
  375:  * return: -1 error, 0 found or 1 not found
  376:  */
  377: int schedQueryby(sched_root_task_t * __restrict root, sched_task_type_t type, 
  378: 		unsigned char criteria, void *param);
  379: 
  380: 
  381: /*
  382:  * schedReadExt() - Add READ I/O task to scheduler queue with custom event mask
  383:  *
  384:  * @root = root task
  385:  * @func = task execution function
  386:  * @arg = 1st func argument
  387:  * @fd = fd handle
  388:  * @opt_data = Optional data
  389:  * @opt_dlen = Optional data length
  390:  * @mask = Event mask
  391:  * return: NULL error or !=NULL new queued task
  392:  */
  393: sched_task_t *schedReadExt(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  394: 		int fd, void *opt_data, size_t opt_dlen, unsigned long mask);
  395: /*
  396:  * schedRead() - Add READ I/O task to scheduler queue
  397:  *
  398:  * @root = root task
  399:  * @func = task execution function
  400:  * @arg = 1st func argument
  401:  * @fd = fd handle
  402:  * @opt_data = Optional data
  403:  * @opt_dlen = Optional data length
  404:  * return: NULL error or !=NULL new queued task
  405:  */
  406: sched_task_t *schedRead(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  407: 		int fd, void *opt_data, size_t opt_dlen);
  408: #define schedReadSelf(x)	schedReadExt(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  409: 		TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)), TASK_HARG((x)))
  410: /*
  411:  * schedWriteExt() - Add WRITE I/O task to scheduler queue with custom event mask
  412:  *
  413:  * @root = root task
  414:  * @func = task execution function
  415:  * @arg = 1st func argument
  416:  * @fd = fd handle
  417:  * @opt_data = Optional data
  418:  * @opt_dlen = Optional data length
  419:  * @mask = Event mask
  420:  * return: NULL error or !=NULL new queued task
  421:  */
  422: sched_task_t *schedWriteExt(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  423: 		int fd, void *opt_data, size_t opt_dlen, unsigned long mask);
  424: /*
  425:  * schedWrite() - Add WRITE I/O task to scheduler queue
  426:  *
  427:  * @root = root task
  428:  * @func = task execution function
  429:  * @arg = 1st func argument
  430:  * @fd = fd handle
  431:  * @opt_data = Optional data
  432:  * @opt_dlen = Optional data length
  433:  * return: NULL error or !=NULL new queued task
  434:  */
  435: sched_task_t *schedWrite(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  436: 		int fd, void *opt_data, size_t opt_dlen);
  437: #define schedWriteSelf(x)	schedWriteExt(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  438: 		TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)), TASK_HARG((x)))
  439: /*
  440:  * schedAlarm() - Add ALARM task to scheduler queue
  441:  *
  442:  * @root = root task
  443:  * @func = task execution function
  444:  * @arg = 1st func argument
  445:  * @ts = timeout argument structure, minimum alarm timer resolution is 1msec!
  446:  * @opt_data = Alarm timer ID
  447:  * @opt_dlen = Optional data length
  448:  * return: NULL error or !=NULL new queued task
  449:  */
  450: sched_task_t *schedAlarm(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  451: 		struct timespec ts, void *opt_data, size_t opt_dlen);
  452: #define schedAlarmSelf(x)	schedAlarm(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  453: 		TASK_TS((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  454: /*
  455:  * schedRTC() - Add RTC task to scheduler queue
  456:  *
  457:  * @root = root task
  458:  * @func = task execution function
  459:  * @arg = 1st func argument
  460:  * @ts = timeout argument structure, minimum alarm timer resolution is 1msec!
  461:  * @opt_data = Optional RTC ID
  462:  * @opt_dlen = Optional data length
  463:  * return: NULL error or !=NULL new queued task
  464:  */
  465: sched_task_t *schedRTC(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  466: 		struct timespec ts, void *opt_data, size_t opt_dlen);
  467: #define schedRTCSelf(x)		schedRTC(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  468: 		TASK_TS((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  469: /*
  470:  * schedNode() - Add NODE task to scheduler queue
  471:  *
  472:  * @root = root task
  473:  * @func = task execution function
  474:  * @arg = 1st func argument
  475:  * @fd = fd handle
  476:  * @opt_data = Optional data
  477:  * @opt_dlen = Optional data length
  478:  * return: NULL error or !=NULL new queued task
  479:  */
  480: sched_task_t *schedNode(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  481: 		int fd, void *opt_data, size_t opt_dlen);
  482: #define schedNodeSelf(x)	schedNode(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  483: 		TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  484: /*
  485:  * schedNode2() - Add NODE task with all events to scheduler queue
  486:  *
  487:  * @root = root task
  488:  * @func = task execution function
  489:  * @arg = 1st func argument
  490:  * @fd = fd handle
  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 *schedNode2(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  496: 		int fd, void *opt_data, size_t opt_dlen);
  497: #define schedNode2Self(x)	schedNode2(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  498: 		TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  499: /*
  500:  * schedProc() - Add PROC task to scheduler queue
  501:  *
  502:  * @root = root task
  503:  * @func = task execution function
  504:  * @arg = 1st func argument
  505:  * @pid = PID
  506:  * @opt_data = Optional data
  507:  * @opt_dlen = Optional data length
  508:  * return: NULL error or !=NULL new queued task
  509:  */
  510: sched_task_t *schedProc(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  511: 		unsigned long pid, void *opt_data, size_t opt_dlen);
  512: #define schedProcSelf(x)	schedProc(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  513: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  514: /*
  515:  * schedSignal() - Add SIGNAL task to scheduler queue
  516:  *
  517:  * @root = root task
  518:  * @func = task execution function
  519:  * @arg = 1st func argument
  520:  * @sig = Signal
  521:  * @opt_data = Optional data
  522:  * @opt_dlen = Optional data length
  523:  * return: NULL error or !=NULL new queued task
  524:  */
  525: sched_task_t *schedSignal(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  526: 		unsigned long sig, void *opt_data, size_t opt_dlen);
  527: #define schedSignalSelf(x)	schedSignal(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  528: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  529: 
  530: #ifdef EVFILT_LIO
  531: /*
  532:  * schedAIO() - Add AIO task to scheduler queue
  533:  *
  534:  * @root = root task
  535:  * @func = task execution function
  536:  * @arg = 1st func argument
  537:  * @acb = AIO cb structure address
  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 *schedAIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  543: 		struct aiocb * __restrict acb, void *opt_data, size_t opt_dlen);
  544: /*
  545:  * schedAIORead() - Add AIO read task to scheduler queue
  546:  *
  547:  * @root = root task
  548:  * @func = task execution function
  549:  * @arg = 1st func argument
  550:  * @fd = file descriptor
  551:  * @buffer = Buffer
  552:  * @buflen = Buffer length
  553:  * @offset = Offset from start of file, if =-1 from current position
  554:  * return: NULL error or !=NULL new queued task
  555:  */
  556: sched_task_t *schedAIORead(sched_root_task_t * __restrict root, sched_task_func_t func, 
  557: 		void *arg, int fd, void *buffer, size_t buflen, off_t offset);
  558: /*
  559:  * schedAIOWrite() - Add AIO write task to scheduler queue
  560:  *
  561:  * @root = root task
  562:  * @func = task execution function
  563:  * @arg = 1st func argument
  564:  * @fd = file descriptor
  565:  * @buffer = Buffer
  566:  * @buflen = Buffer length
  567:  * @offset = Offset from start of file, if =-1 from current position
  568:  * return: NULL error or !=NULL new queued task
  569:  */
  570: sched_task_t *schedAIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func, 
  571: 		void *arg, int fd, void *buffer, size_t buflen, off_t offset);
  572: 
  573: /*
  574:  * schedLIO() - Add AIO bulk tasks to scheduler queue
  575:  *
  576:  * @root = root task
  577:  * @func = task execution function
  578:  * @arg = 1st func argument
  579:  * @acbs = AIO cb structure addresses
  580:  * @opt_data = Optional data
  581:  * @opt_dlen = Optional data length
  582:  * return: NULL error or !=NULL new queued task
  583:  */
  584: sched_task_t *schedLIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  585: 		struct aiocb ** __restrict acbs, void *opt_data, size_t opt_dlen);
  586: /*
  587:  * schedLIORead() - Add list of AIO read tasks to scheduler queue
  588:  *
  589:  * @root = root task
  590:  * @func = task execution function
  591:  * @arg = 1st func argument
  592:  * @fd = file descriptor
  593:  * @bufs = Buffer's list
  594:  * @nbufs = Number of Buffers
  595:  * @offset = Offset from start of file, if =-1 from current position
  596:  * return: NULL error or !=NULL new queued task
  597:  */
  598: sched_task_t *schedLIORead(sched_root_task_t * __restrict root, sched_task_func_t func, 
  599: 		void *arg, int fd, struct iovec *bufs, size_t nbufs, off_t offset);
  600: /*
  601:  * schedLIOWrite() - Add list of AIO write tasks to scheduler queue
  602:  *
  603:  * @root = root task
  604:  * @func = task execution function
  605:  * @arg = 1st func argument
  606:  * @fd = file descriptor
  607:  * @bufs = Buffer's list
  608:  * @nbufs = Number of Buffers
  609:  * @offset = Offset from start of file, if =-1 from current position
  610:  * return: NULL error or !=NULL new queued task
  611:  */
  612: sched_task_t *schedLIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func, 
  613: 		void *arg, int fd, struct iovec *bufs, size_t nbufs, off_t offset);
  614: #endif	/* EVFILT_LIO */
  615: 
  616: /*
  617:  * schedUser() - Add trigger USER task to scheduler queue
  618:  *
  619:  * @root = root task
  620:  * @func = task execution function
  621:  * @arg = 1st func argument
  622:  * @id = Trigger ID
  623:  * @opt_data = Optional data
  624:  * @opt_dlen = Optional user's trigger flags
  625:  * return: NULL error or !=NULL new queued task
  626:  */
  627: sched_task_t *schedUser(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  628: 		unsigned long id, void *opt_data, size_t opt_dlen);
  629: #define schedUserSelf(x)	schedUser(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  630: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  631: /*
  632:  * schedTrigger() - Triggering USER task
  633:  *
  634:  * @task = task
  635:  * return: -1 error or 0 ok
  636:  */
  637: int schedTrigger(sched_task_t * __restrict task);
  638: 
  639: /*
  640:  * schedTimer() - Add TIMER task to scheduler queue
  641:  *
  642:  * @root = root task
  643:  * @func = task execution function
  644:  * @arg = 1st func argument
  645:  * @ts = timeout argument structure
  646:  * @opt_data = Optional data
  647:  * @opt_dlen = Optional data length
  648:  * return: NULL error or !=NULL new queued task
  649:  */
  650: sched_task_t *schedTimer(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  651: 		struct timespec ts, void *opt_data, size_t opt_dlen);
  652: /*
  653:  * schedEvent() - Add EVENT task to scheduler queue
  654:  *
  655:  * @root = root task
  656:  * @func = task execution function
  657:  * @arg = 1st func argument
  658:  * @val = additional func argument
  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 *schedEvent(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  664: 		unsigned long val, void *opt_data, size_t opt_dlen);
  665: #define schedEventSelf(x)	schedEvent(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  666: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  667: /*
  668:  * schedTask() - Add regular task to scheduler queue
  669:  *
  670:  * @root = root task
  671:  * @func = task execution function
  672:  * @arg = 1st func argument
  673:  * @prio = regular task priority, 0 is hi priority for regular tasks
  674:  * @opt_data = Optional data
  675:  * @opt_dlen = Optional data length
  676:  * return: NULL error or !=NULL new queued task
  677:  */
  678: sched_task_t *schedTask(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  679: 		unsigned long prio, void *opt_data, size_t opt_dlen);
  680: #define schedTaskSelf(x)	schedTask(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  681: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  682: /*
  683:  * schedSuspend() - Add Suspended task to scheduler queue
  684:  *
  685:  * @root = root task
  686:  * @func = task execution function
  687:  * @arg = 1st func argument
  688:  * @id = Trigger ID
  689:  * @opt_data = Optional data
  690:  * @opt_dlen = Optional user's trigger flags
  691:  * return: NULL error or !=NULL new queued task
  692:  */
  693: sched_task_t *schedSuspend(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  694: 		unsigned long id, void *opt_data, size_t opt_dlen);
  695: #define schedSuspendSelf(x)	schedUser(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  696: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  697: /*
  698:  * schedResumeby() - Resume suspended task
  699:  *
  700:  * @root = root task
  701:  * @criteria = find task by criteria 
  702:  * 	[ CRITERIA_ANY|CRITERIA_ID|CRITERIA_VAL|CRITERIA_DATA ]
  703:  * @param = search parameter (sched_task_t *task| unsigned long id)
  704:  * return: -1 error or 0 resumed ok
  705:  */
  706: int schedResumeby(sched_root_task_t * __restrict root, unsigned char criteria, void *param);
  707: 
  708: /*
  709:  * schedCallOnce() - Call once from scheduler
  710:  *
  711:  * @root = root task
  712:  * @func = task execution function
  713:  * @arg = 1st func argument
  714:  * @val = additional func argument
  715:  * @opt_data = Optional data
  716:  * @opt_dlen = Optional data length
  717:  * return: return value from called func
  718:  */
  719: sched_task_t *schedCallOnce(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  720: 		unsigned long val, void *opt_data, size_t opt_dlen);
  721: #define schedCallAgain(x)	schedCallOnce(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  722: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  723: 
  724: /*
  725:  * schedThread() - Add thread task to scheduler queue
  726:  *
  727:  * @root = root task
  728:  * @func = task execution function
  729:  * @arg = 1st func argument
  730:  * @ss = stack size
  731:  * @opt_data = Optional data
  732:  * @opt_dlen = Optional data length
  733:  * return: NULL error or !=NULL new queued task
  734:  */
  735: sched_task_t *schedThread(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  736: 		size_t ss, void *opt_data, size_t opt_dlen);
  737: #define schedThreadSelf(x)	schedThread(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  738: 		(size_t) TASK_FLAG((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  739: /*
  740:  * sched_taskExit() - Exit routine for scheduler task, explicit required for thread tasks
  741:  *
  742:  * @task = current task
  743:  * @retcode = return code
  744:  * return: return code
  745:  */
  746: void *sched_taskExit(sched_task_t *task, intptr_t retcode);
  747: /*
  748:  * taskExit() - Exit helper for scheduler task
  749:  *
  750:  * @t = current executed task
  751:  * @x = exit value for task
  752:  * return: none
  753:  */
  754: #define taskExit(t, x)		return sched_taskExit((t), (intptr_t) (x))
  755: 
  756: 
  757: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>