File:  [ELWIX - Embedded LightWeight unIX -] / libaitsched / inc / aitsched.h
Revision 1.29: download - view: text, annotated - select for diffs - revision graph
Mon Jan 14 15:58:50 2019 UTC (5 years, 5 months ago) by misho
Branches: MAIN
CVS tags: sched7_1, sched7_0, sched6_9, sched6_8, sched6_7, SCHED7_0, SCHED6_9, SCHED6_8, SCHED6_7, SCHED6_6, HEAD
version 6.6

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

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