File:  [ELWIX - Embedded LightWeight unIX -] / libaitsched / inc / aitsched.h
Revision 1.21: download - view: text, annotated - select for diffs - revision graph
Thu Aug 22 15:28:04 2013 UTC (10 years, 10 months ago) by misho
Branches: MAIN
CVS tags: sched4_2, sched4_1, sched3_10, SCHED4_1, SCHED4_0, SCHED3_9, HEAD
version 3.9

    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.21 2013/08/22 15:28:04 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|CRITERIA_ID|CRITERIA_TS|CRITERIA_DATA]
  343:  * @param = search parameter
  344:  * @hook = custom cleanup hook function, may be NULL
  345:  * return: -1 error, -2 error in sub-stage cancel execution, -3 error from custom hook or 0 ok
  346:  */
  347: int schedCancelby(sched_root_task_t * __restrict root, sched_task_type_t type, 
  348: 		u_char criteria, void *param, sched_hook_func_t hook);
  349: 
  350: 
  351: /*
  352:  * schedRead() - Add READ I/O task to scheduler queue
  353:  *
  354:  * @root = root task
  355:  * @func = task execution function
  356:  * @arg = 1st func argument
  357:  * @fd = fd handle
  358:  * @opt_data = Optional data
  359:  * @opt_dlen = Optional data length
  360:  * return: NULL error or !=NULL new queued task
  361:  */
  362: sched_task_t *schedRead(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  363: 		int fd, void *opt_data, size_t opt_dlen);
  364: #define schedReadSelf(x)	schedRead(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  365: 		TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  366: /*
  367:  * schedWrite() - Add WRITE I/O task to scheduler queue
  368:  *
  369:  * @root = root task
  370:  * @func = task execution function
  371:  * @arg = 1st func argument
  372:  * @fd = fd handle
  373:  * @opt_data = Optional data
  374:  * @opt_dlen = Optional data length
  375:  * return: NULL error or !=NULL new queued task
  376:  */
  377: sched_task_t *schedWrite(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  378: 		int fd, void *opt_data, size_t opt_dlen);
  379: #define schedWriteSelf(x)	schedWrite(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  380: 		TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  381: /*
  382:  * schedAlarm() - Add ALARM task to scheduler queue
  383:  *
  384:  * @root = root task
  385:  * @func = task execution function
  386:  * @arg = 1st func argument
  387:  * @ts = timeout argument structure, minimum alarm timer resolution is 1msec!
  388:  * @opt_data = Alarm timer ID
  389:  * @opt_dlen = Optional data length
  390:  * return: NULL error or !=NULL new queued task
  391:  */
  392: sched_task_t *schedAlarm(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  393: 		struct timespec ts, void *opt_data, size_t opt_dlen);
  394: #define schedAlarmSelf(x)	schedAlarm(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  395: 		TASK_TS((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  396: /*
  397:  * schedRTC() - Add RTC task to scheduler queue
  398:  *
  399:  * @root = root task
  400:  * @func = task execution function
  401:  * @arg = 1st func argument
  402:  * @ts = timeout argument structure, minimum alarm timer resolution is 1msec!
  403:  * @opt_data = Optional RTC ID
  404:  * @opt_dlen = Optional data length
  405:  * return: NULL error or !=NULL new queued task
  406:  */
  407: sched_task_t *schedRTC(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  408: 		struct timespec ts, void *opt_data, size_t opt_dlen);
  409: #define schedRTCSelf(x)		schedRTC(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  410: 		TASK_TS((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  411: /*
  412:  * schedNode() - Add NODE task to scheduler queue
  413:  *
  414:  * @root = root task
  415:  * @func = task execution function
  416:  * @arg = 1st func argument
  417:  * @fd = fd handle
  418:  * @opt_data = Optional data
  419:  * @opt_dlen = Optional data length
  420:  * return: NULL error or !=NULL new queued task
  421:  */
  422: sched_task_t *schedNode(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  423: 		int fd, void *opt_data, size_t opt_dlen);
  424: #define schedNodeSelf(x)	schedNode(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  425: 		TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  426: /*
  427:  * schedProc() - Add PROC task to scheduler queue
  428:  *
  429:  * @root = root task
  430:  * @func = task execution function
  431:  * @arg = 1st func argument
  432:  * @pid = PID
  433:  * @opt_data = Optional data
  434:  * @opt_dlen = Optional data length
  435:  * return: NULL error or !=NULL new queued task
  436:  */
  437: sched_task_t *schedProc(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  438: 		unsigned long pid, void *opt_data, size_t opt_dlen);
  439: #define schedProcSelf(x)	schedProc(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  440: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  441: /*
  442:  * schedSignal() - Add SIGNAL task to scheduler queue
  443:  *
  444:  * @root = root task
  445:  * @func = task execution function
  446:  * @arg = 1st func argument
  447:  * @sig = Signal
  448:  * @opt_data = Optional data
  449:  * @opt_dlen = Optional data length
  450:  * return: NULL error or !=NULL new queued task
  451:  */
  452: sched_task_t *schedSignal(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  453: 		unsigned long sig, void *opt_data, size_t opt_dlen);
  454: #define schedSignalSelf(x)	schedSignal(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  455: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  456: 
  457: #ifdef EVFILT_LIO
  458: /*
  459:  * schedAIO() - Add AIO task to scheduler queue
  460:  *
  461:  * @root = root task
  462:  * @func = task execution function
  463:  * @arg = 1st func argument
  464:  * @acb = AIO cb structure address
  465:  * @opt_data = Optional data
  466:  * @opt_dlen = Optional data length
  467:  * return: NULL error or !=NULL new queued task
  468:  */
  469: sched_task_t *schedAIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  470: 		struct aiocb * __restrict acb, void *opt_data, size_t opt_dlen);
  471: /*
  472:  * schedAIORead() - Add AIO read task to scheduler queue
  473:  *
  474:  * @root = root task
  475:  * @func = task execution function
  476:  * @arg = 1st func argument
  477:  * @fd = file descriptor
  478:  * @buffer = Buffer
  479:  * @buflen = Buffer length
  480:  * @offset = Offset from start of file, if =-1 from current position
  481:  * return: NULL error or !=NULL new queued task
  482:  */
  483: sched_task_t *schedAIORead(sched_root_task_t * __restrict root, sched_task_func_t func, 
  484: 		void *arg, int fd, void *buffer, size_t buflen, off_t offset);
  485: /*
  486:  * schedAIOWrite() - Add AIO write task to scheduler queue
  487:  *
  488:  * @root = root task
  489:  * @func = task execution function
  490:  * @arg = 1st func argument
  491:  * @fd = file descriptor
  492:  * @buffer = Buffer
  493:  * @buflen = Buffer length
  494:  * @offset = Offset from start of file, if =-1 from current position
  495:  * return: NULL error or !=NULL new queued task
  496:  */
  497: sched_task_t *schedAIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func, 
  498: 		void *arg, int fd, void *buffer, size_t buflen, off_t offset);
  499: 
  500: /*
  501:  * schedLIO() - Add AIO bulk tasks to scheduler queue
  502:  *
  503:  * @root = root task
  504:  * @func = task execution function
  505:  * @arg = 1st func argument
  506:  * @acbs = AIO cb structure addresses
  507:  * @opt_data = Optional data
  508:  * @opt_dlen = Optional data length
  509:  * return: NULL error or !=NULL new queued task
  510:  */
  511: sched_task_t *schedLIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  512: 		struct aiocb ** __restrict acbs, void *opt_data, size_t opt_dlen);
  513: /*
  514:  * schedLIORead() - Add list of AIO read tasks to scheduler queue
  515:  *
  516:  * @root = root task
  517:  * @func = task execution function
  518:  * @arg = 1st func argument
  519:  * @fd = file descriptor
  520:  * @bufs = Buffer's list
  521:  * @nbufs = Number of Buffers
  522:  * @offset = Offset from start of file, if =-1 from current position
  523:  * return: NULL error or !=NULL new queued task
  524:  */
  525: sched_task_t *schedLIORead(sched_root_task_t * __restrict root, sched_task_func_t func, 
  526: 		void *arg, int fd, struct iovec *bufs, size_t nbufs, off_t offset);
  527: /*
  528:  * schedLIOWrite() - Add list of AIO write tasks to scheduler queue
  529:  *
  530:  * @root = root task
  531:  * @func = task execution function
  532:  * @arg = 1st func argument
  533:  * @fd = file descriptor
  534:  * @bufs = Buffer's list
  535:  * @nbufs = Number of Buffers
  536:  * @offset = Offset from start of file, if =-1 from current position
  537:  * return: NULL error or !=NULL new queued task
  538:  */
  539: sched_task_t *schedLIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func, 
  540: 		void *arg, int fd, struct iovec *bufs, size_t nbufs, off_t offset);
  541: #endif	/* EVFILT_LIO */
  542: 
  543: /*
  544:  * schedUser() - Add trigger USER task to scheduler queue
  545:  *
  546:  * @root = root task
  547:  * @func = task execution function
  548:  * @arg = 1st func argument
  549:  * @id = Trigger ID
  550:  * @opt_data = Optional data
  551:  * @opt_dlen = Optional user's trigger flags
  552:  * return: NULL error or !=NULL new queued task
  553:  */
  554: sched_task_t *schedUser(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  555: 		unsigned long id, void *opt_data, size_t opt_dlen);
  556: #define schedUserSelf(x)	schedUser(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  557: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  558: /*
  559:  * schedTrigger() - Triggering USER task
  560:  *
  561:  * @task = task
  562:  * return: -1 error or 0 ok
  563:  */
  564: int schedTrigger(sched_task_t * __restrict task);
  565: 
  566: /*
  567:  * schedTimer() - Add TIMER task to scheduler queue
  568:  *
  569:  * @root = root task
  570:  * @func = task execution function
  571:  * @arg = 1st func argument
  572:  * @ts = timeout argument structure
  573:  * @opt_data = Optional data
  574:  * @opt_dlen = Optional data length
  575:  * return: NULL error or !=NULL new queued task
  576:  */
  577: sched_task_t *schedTimer(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  578: 		struct timespec ts, void *opt_data, size_t opt_dlen);
  579: /*
  580:  * schedEvent() - Add EVENT task to scheduler queue
  581:  *
  582:  * @root = root task
  583:  * @func = task execution function
  584:  * @arg = 1st func argument
  585:  * @val = additional func argument
  586:  * @opt_data = Optional data
  587:  * @opt_dlen = Optional data length
  588:  * return: NULL error or !=NULL new queued task
  589:  */
  590: sched_task_t *schedEvent(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  591: 		unsigned long val, void *opt_data, size_t opt_dlen);
  592: #define schedEventSelf(x)	schedEvent(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  593: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  594: /*
  595:  * schedTask() - Add regular task to scheduler queue
  596:  *
  597:  * @root = root task
  598:  * @func = task execution function
  599:  * @arg = 1st func argument
  600:  * @prio = regular task priority, 0 is hi priority for regular tasks
  601:  * @opt_data = Optional data
  602:  * @opt_dlen = Optional data length
  603:  * return: NULL error or !=NULL new queued task
  604:  */
  605: sched_task_t *schedTask(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  606: 		unsigned long prio, void *opt_data, size_t opt_dlen);
  607: #define schedTaskSelf(x)	schedTask(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  608: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  609: /*
  610:  * schedSuspend() - Add Suspended task to scheduler queue
  611:  *
  612:  * @root = root task
  613:  * @func = task execution function
  614:  * @arg = 1st func argument
  615:  * @id = Trigger ID
  616:  * @opt_data = Optional data
  617:  * @opt_dlen = Optional user's trigger flags
  618:  * return: NULL error or !=NULL new queued task
  619:  */
  620: sched_task_t *schedSuspend(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  621: 		unsigned long id, void *opt_data, size_t opt_dlen);
  622: #define schedSuspendSelf(x)	schedUser(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  623: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  624: /*
  625:  * schedResumeby() - Resume suspended task
  626:  *
  627:  * @root = root task
  628:  * @criteria = find task by criteria 
  629:  * 	[CRITERIA_ANY|CRITERIA_ID|CRITERIA_DATA]
  630:  * @param = search parameter (sched_task_t *task| u_long id)
  631:  * return: -1 error or 0 resumed ok
  632:  */
  633: int schedResumeby(sched_root_task_t * __restrict root, unsigned char criteria, void *param);
  634: 
  635: /*
  636:  * schedCallOnce() - Call once from scheduler
  637:  *
  638:  * @root = root task
  639:  * @func = task execution function
  640:  * @arg = 1st func argument
  641:  * @val = additional func argument
  642:  * @opt_data = Optional data
  643:  * @opt_dlen = Optional data length
  644:  * return: return value from called func
  645:  */
  646: sched_task_t *schedCallOnce(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  647: 		unsigned long val, void *opt_data, size_t opt_dlen);
  648: #define schedCallAgain(x)	schedCallOnce(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  649: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  650: 
  651: /*
  652:  * schedThread() - Add thread task to scheduler queue
  653:  *
  654:  * @root = root task
  655:  * @func = task execution function
  656:  * @arg = 1st func argument
  657:  * @detach = Detach thread from scheduler, if !=0
  658:  * @ss = stack size
  659:  * @opt_data = Optional data
  660:  * @opt_dlen = Optional data length
  661:  * return: NULL error or !=NULL new queued task
  662:  */
  663: sched_task_t *schedThread(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  664: 		int detach, size_t ss, void *opt_data, size_t opt_dlen);
  665: #define schedThreadSelf(x)	schedThread(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  666: 		(TASK_FLAG((x)) & 0x1), (size_t) (TASK_FLAG((x)) >> 1), TASK_DATA((x)), TASK_DATLEN((x)))
  667: /*
  668:  * sched_taskExit() - Exit routine for scheduler task, explicit required for thread tasks
  669:  *
  670:  * @task = current task
  671:  * @retcode = return code
  672:  * return: return code
  673:  */
  674: void *sched_taskExit(sched_task_t *task, intptr_t retcode);
  675: /*
  676:  * taskExit() - Exit helper for scheduler task
  677:  *
  678:  * @t = current executed task
  679:  * @x = exit value for task
  680:  * return: none
  681:  */
  682: #define taskExit(t, x)		return sched_taskExit((t), (intptr_t) (x))
  683: 
  684: 
  685: #endif

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