File:  [ELWIX - Embedded LightWeight unIX -] / libaitsched / inc / aitsched.h
Revision 1.23: download - view: text, annotated - select for diffs - revision graph
Mon Oct 21 13:38:05 2013 UTC (10 years, 8 months ago) by misho
Branches: MAIN
CVS tags: sched4_6, sched4_5, SCHED4_5, SCHED4_4, HEAD
version 4.4

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

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