File:  [ELWIX - Embedded LightWeight unIX -] / libaitsched / inc / aitsched.h
Revision 1.13: download - view: text, annotated - select for diffs - revision graph
Wed Aug 8 08:25:39 2012 UTC (11 years, 11 months ago) by misho
Branches: MAIN
CVS tags: sched3_1, SCHED3_0, HEAD
version 3.0

    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.13 2012/08/08 08:25:39 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
   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: #ifdef EVFILT_LIO
   57: #include <aio.h>
   58: #endif
   59: 
   60: 
   61: /* criteria type */
   62: #define CRITERIA_ANY	0
   63: #define CRITERIA_CALL	1
   64: #define CRITERIA_ARG	2
   65: #define CRITERIA_FD	3
   66: #define CRITERIA_VAL	4
   67: #define CRITERIA_TS	5
   68: #define CRITERIA_DATA	6
   69: #define CRITERIA_ID	7
   70: 
   71: 
   72: /* early declaration for root & task */
   73: typedef struct sched_Task	sched_task_t;
   74: typedef struct sched_RootTask	sched_root_task_t;
   75: 
   76: typedef enum {
   77: 	taskREAD = 0,
   78: 	taskWRITE,
   79: 	taskTIMER,
   80: 	taskALARM,
   81: 	taskNODE,
   82: 	taskPROC,
   83: 	taskSIGNAL,
   84: 	taskAIO,
   85: 	taskLIO,
   86: 	taskUSER,
   87: 	taskEVENT,
   88: 	taskTASK,
   89: 	taskSUSPEND, 
   90: 	taskREADY,
   91: 	taskUNUSE,
   92: 	taskMAX
   93: } sched_task_type_t;
   94: 
   95: /* hooks */
   96: typedef void *(*sched_hook_func_t)(void *, void *);
   97: struct sched_HooksTask {
   98: 	struct {
   99: 		/* read(sched_task_t *task, NULL) -> int */
  100: 		sched_hook_func_t	read;
  101: 		/* write(sched_task_t *task, NULL) -> int */
  102: 		sched_hook_func_t	write;
  103: 		/* timer(sched_task_t *task, struct timespec *ts) -> int */
  104: 		sched_hook_func_t	timer;
  105: 		/* alarm(sched_task_t *task, NULL) -> int */
  106: 		sched_hook_func_t	alarm;
  107: 		/* node(sched_task_t *task, NULL) -> int */
  108: 		sched_hook_func_t	node;
  109: 		/* proc(sched_task_t *task, NULL) -> int */
  110: 		sched_hook_func_t	proc;
  111: 		/* signal(sched_task_t *task, NULL) -> int */
  112: 		sched_hook_func_t	signal;
  113: 		/* aio(sched_task_t *task, NULL) -> int */
  114: 		sched_hook_func_t	aio;
  115: 		/* lio(sched_task_t *task, NULL) -> int */
  116: 		sched_hook_func_t	lio;
  117: 		/* user(sched_task_t *task, NULL) -> int */
  118: 		sched_hook_func_t	user;
  119: 		/* event(sched_task_t *task, NULL) -> int */
  120: 		sched_hook_func_t	event;
  121: 		/* task(sched_task_t *task, NULL) -> int */
  122: 		sched_hook_func_t	task;
  123: 		/* suspend(sched_task_t *task, NULL) -> int */
  124: 		sched_hook_func_t	suspend;
  125: 	}	hook_add;
  126: 	struct {
  127: 		/* cancel(sched_task_t *task, NULL) -> int */
  128: 		sched_hook_func_t	cancel;
  129: 		/* resume(sched_task_t *task, NULL) -> int */
  130: 		sched_hook_func_t	resume;
  131: 		/* run(sched_root_task_t *root, NULL) -> int */
  132: 		sched_hook_func_t	run;
  133: 		/* fetch(sched_root_task_t *root, NULL) -> sched_task_t* */
  134: 		sched_hook_func_t	fetch;
  135: 		/* exception(sched_root_task_t *root, NULL) -> int */
  136: 		sched_hook_func_t	exception;
  137: 		/* condition(sched_root_task_t *root, intptr_t *stopValue) -> int */
  138: 		sched_hook_func_t	condition;
  139: 	}	hook_exec;
  140: 	struct {
  141: 		/* init(sched_root_task_t *root, void *data) -> int */
  142: 		sched_hook_func_t	init;
  143: 		/* fini(sched_root_task_t *root, NULL) -> int */
  144: 		sched_hook_func_t	fini;
  145: 		/* error(sched_root_task_t *root, int errno) -> int */
  146: 		sched_hook_func_t	error;
  147: 	}	hook_root;
  148: };
  149: typedef struct sched_HooksTask hooks_task_t;
  150: 
  151: /* task callback, like pthread callback! */
  152: typedef void *(*sched_task_func_t)(sched_task_t * /* current task data*/);
  153: 
  154: /* task lock helpers */
  155: #define TASK_LOCK(x)		((x)->task_lock = 42)
  156: #define TASK_UNLOCK(x)		((x)->task_lock ^= (x)->task_lock)
  157: #define TASK_ISLOCKED(x)	((x)->task_lock)
  158: 
  159: /* task & queue */
  160: struct sched_Task {
  161: 	volatile int			task_lock;
  162: 	uintptr_t			task_id;
  163: #define TASK_ID(x)	((struct sched_Task*) (x)->task_id)
  164: 	sched_task_type_t		task_type;
  165: #define TASK_TYPE(x)	(x)->task_type
  166: 
  167: 	sched_root_task_t		*task_root;
  168: #define TASK_ROOT(x)	(x)->task_root
  169: 	sched_task_func_t		task_func;
  170: #define TASK_FUNC(x)	(x)->task_func
  171: 
  172: 	void				*task_arg;
  173: 	union {
  174: 		unsigned long	v;
  175: 		intptr_t	fd;
  176: 		struct timespec	ts;
  177: 	}				task_val;
  178: #define TASK_ARG(x)	(x)->task_arg
  179: #define TASK_VAL(x)	(x)->task_val.v
  180: #define TASK_FD(x)	(x)->task_val.fd
  181: #define TASK_TS(x)	(x)->task_val.ts
  182: 
  183: 	struct iovec			task_data;
  184: #define TASK_DATA(x)	(x)->task_data.iov_base
  185: #define TASK_DATLEN(x)	(x)->task_data.iov_len
  186: 
  187: 	TAILQ_ENTRY(sched_Task)		task_node;
  188: };
  189: typedef TAILQ_HEAD(, sched_Task) sched_queue_t;
  190: #define TASK_DATA_SET(x, _dp, _dl)	do { \
  191: 						if ((x)) { \
  192: 							(x)->task_data.iov_base = (_dp); \
  193: 							(x)->task_data.iov_len = _dl; \
  194: 						} \
  195: 					while (0)
  196: 
  197: /* root task */
  198: struct sched_RootTask {
  199: 	int		root_kq;
  200: 	unsigned int	root_miss;
  201: 	unsigned int	root_task_miss;
  202: 	struct timespec	root_wait;
  203: 	struct timespec	root_poll;
  204: 	intptr_t	root_cond;
  205: 	void		*root_ret;
  206: 
  207: 	pthread_mutex_t	root_mtx[taskMAX];
  208: 
  209: 	sched_queue_t	root_read;
  210: 	sched_queue_t	root_write;
  211: 	sched_queue_t	root_timer;
  212: 	sched_queue_t	root_alarm;
  213: 	sched_queue_t	root_node;
  214: 	sched_queue_t	root_proc;
  215: 	sched_queue_t	root_signal;
  216: 	sched_queue_t	root_aio;
  217: 	sched_queue_t	root_lio;
  218: 	sched_queue_t	root_user;
  219: 	sched_queue_t	root_event;
  220: 	sched_queue_t	root_task;
  221: 	sched_queue_t	root_suspend;
  222: 	sched_queue_t	root_ready;
  223: 	sched_queue_t	root_unuse;
  224: 
  225: 	hooks_task_t	root_hooks;
  226: 	struct iovec	root_data;
  227: #define ROOT_DATA(x)	(x)->root_data.iov_base
  228: #define ROOT_DATLEN(x)	(x)->root_data.iov_len
  229: };
  230: #define ROOT_QUEUE_EMPTY(x, _q)	TAILQ_EMPTY(&((x)->root_##_q))
  231: #define ROOT_RETURN(x)	(x)->root_ret
  232: 
  233: 
  234: inline int sched_GetErrno();
  235: inline const char *sched_GetError();
  236: 
  237: 
  238: /*
  239:  * schedInit() - Init scheduler
  240:  *
  241:  * @data = optional data if !=NULL
  242:  * @datlen = data len if data is set
  243:  * return: allocated root task if ok or NULL error
  244:  */
  245: sched_root_task_t *schedInit(void ** __restrict data, size_t datlen);
  246: #define schedBegin()	schedInit((void**) &schedRegisterHooks, 0)
  247: /*
  248:  * schedEnd() - End scheduler & free all resources
  249:  *
  250:  * @root = root task
  251:  * return: -1 error or 0 ok
  252:  */
  253: int schedEnd(sched_root_task_t ** __restrict root);
  254: /*
  255:  * schedRegisterHooks() - Register IO handles and bind tasks to it
  256:  *
  257:  * @root = root task
  258:  * return: -1 error or 0 ok
  259:  */
  260: int schedRegisterHooks(sched_root_task_t * __restrict root);
  261: /*
  262:  * schedPolling() - Polling timeout period if no timer task is present
  263:  *
  264:  * @root = root task
  265:  * @ts = timeout polling period, if ==NULL INFINIT timeout
  266:  * @tsold = old timeout polling if !=NULL
  267:  * return: -1 error or 0 ok
  268:  */
  269: inline int schedPolling(sched_root_task_t * __restrict root, 
  270: 		struct timespec * __restrict ts, struct timespec * __restrict tsold);
  271: /*
  272:  * schedTermCondition() - Activate hook for scheduler condition kill
  273:  *
  274:  * @root = root task
  275:  * @condValue = condition value, kill schedRun() if condValue == killState
  276:  * return: -1 error or 0 ok
  277:  */
  278: inline int schedTermCondition(sched_root_task_t * __restrict root, intptr_t condValue);
  279: /*
  280:  * schedMissEvents() - Set new miss events rate for regular tasks
  281:  *
  282:  * @root = root task
  283:  * @missEvents = maximum number of missed events before firing tasks
  284:  * return: -1 error or 0 ok
  285:  */
  286: inline int schedMissEvents(sched_root_task_t * __restrict root, u_int missEvents);
  287: /*
  288:  * schedCall() - Call task execution function
  289:  *
  290:  * @task = current task
  291:  * return: !=NULL error or =NULL ok
  292:  */
  293: inline void *schedCall(sched_task_t * __restrict task);
  294: /*
  295:  * schedFetch() - Fetch ready task
  296:  *
  297:  * @root = root task
  298:  * return: =NULL error or !=NULL ready task
  299:  */
  300: inline void *schedFetch(sched_root_task_t * __restrict root);
  301: /*
  302:  * schedRun() - Scheduler *run loop*
  303:  *
  304:  * @root = root task
  305:  * @killState = kill condition variable, if !=0 stop scheduler loop
  306:  * return: -1 error or 0 ok
  307:  */
  308: int schedRun(sched_root_task_t *root, volatile intptr_t * __restrict killState);
  309: /*
  310:  * schedCancel() - Cancel task from scheduler
  311:  *
  312:  * @task = task
  313:  * return: -1 error or 0 ok
  314:  */
  315: int schedCancel(sched_task_t * __restrict task);
  316: /*
  317:  * schedCancelby() - Cancel task from scheduler by criteria
  318:  *
  319:  * @root = root task
  320:  * @type = cancel from queue type, if =taskMAX cancel same task from all queues
  321:  * @criteria = find task by criteria 
  322:  * 	[CRITERIA_ANY|CRITERIA_CALL|CRITERIA_ARG|CRITERIA_FD|CRITERIA_VAL|CRITERIA_ID|CRITERIA_TS|CRITERIA_DATA]
  323:  * @param = search parameter
  324:  * @hook = custom cleanup hook function, may be NULL
  325:  * return: -1 error, -2 error in sub-stage cancel execution, -3 error from custom hook or 0 ok
  326:  */
  327: int schedCancelby(sched_root_task_t * __restrict root, sched_task_type_t type, 
  328: 		u_char criteria, void *param, sched_hook_func_t hook);
  329: 
  330: 
  331: /*
  332:  * schedRead() - Add READ I/O task to scheduler queue
  333:  *
  334:  * @root = root task
  335:  * @func = task execution function
  336:  * @arg = 1st func argument
  337:  * @fd = fd handle
  338:  * @opt_data = Optional data
  339:  * @opt_dlen = Optional data length
  340:  * return: NULL error or !=NULL new queued task
  341:  */
  342: sched_task_t *schedRead(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  343: 		int fd, void *opt_data, size_t opt_dlen);
  344: #define schedReadSelf(x)	schedRead(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  345: 		TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  346: /*
  347:  * schedWrite() - Add WRITE I/O task to scheduler queue
  348:  *
  349:  * @root = root task
  350:  * @func = task execution function
  351:  * @arg = 1st func argument
  352:  * @fd = fd handle
  353:  * @opt_data = Optional data
  354:  * @opt_dlen = Optional data length
  355:  * return: NULL error or !=NULL new queued task
  356:  */
  357: sched_task_t *schedWrite(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  358: 		int fd, void *opt_data, size_t opt_dlen);
  359: #define schedWriteSelf(x)	schedWrite(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  360: 		TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  361: /*
  362:  * schedAlarm() - Add ALARM task to scheduler queue
  363:  *
  364:  * @root = root task
  365:  * @func = task execution function
  366:  * @arg = 1st func argument
  367:  * @ts = timeout argument structure, minimum alarm timer resolution is 1msec!
  368:  * @opt_data = Optional data
  369:  * @opt_dlen = Optional data length
  370:  * return: NULL error or !=NULL new queued task
  371:  */
  372: sched_task_t *schedAlarm(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  373: 		struct timespec ts, void *opt_data, size_t opt_dlen);
  374: #define schedAlarmSelf(x)	schedAlarm(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  375: 		TASK_TS((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  376: /*
  377:  * schedNode() - Add NODE task to scheduler queue
  378:  *
  379:  * @root = root task
  380:  * @func = task execution function
  381:  * @arg = 1st func argument
  382:  * @fd = fd handle
  383:  * @opt_data = Optional data
  384:  * @opt_dlen = Optional data length
  385:  * return: NULL error or !=NULL new queued task
  386:  */
  387: sched_task_t *schedNode(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  388: 		int fd, void *opt_data, size_t opt_dlen);
  389: #define schedNodeSelf(x)	schedNode(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  390: 		TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  391: /*
  392:  * schedProc() - Add PROC task to scheduler queue
  393:  *
  394:  * @root = root task
  395:  * @func = task execution function
  396:  * @arg = 1st func argument
  397:  * @pid = PID
  398:  * @opt_data = Optional data
  399:  * @opt_dlen = Optional data length
  400:  * return: NULL error or !=NULL new queued task
  401:  */
  402: sched_task_t *schedProc(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  403: 		unsigned long pid, void *opt_data, size_t opt_dlen);
  404: #define schedProcSelf(x)	schedProc(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  405: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  406: /*
  407:  * schedSignal() - Add SIGNAL task to scheduler queue
  408:  *
  409:  * @root = root task
  410:  * @func = task execution function
  411:  * @arg = 1st func argument
  412:  * @sig = Signal
  413:  * @opt_data = Optional data
  414:  * @opt_dlen = Optional data length
  415:  * return: NULL error or !=NULL new queued task
  416:  */
  417: sched_task_t *schedSignal(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  418: 		unsigned long sig, void *opt_data, size_t opt_dlen);
  419: #define schedSignalSelf(x)	schedSignal(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  420: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  421: 
  422: #ifdef EVFILT_LIO
  423: /*
  424:  * schedAIO() - Add AIO task to scheduler queue
  425:  *
  426:  * @root = root task
  427:  * @func = task execution function
  428:  * @arg = 1st func argument
  429:  * @acb = AIO cb structure address
  430:  * @opt_data = Optional data
  431:  * @opt_dlen = Optional data length
  432:  * return: NULL error or !=NULL new queued task
  433:  */
  434: sched_task_t *schedAIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  435: 		struct aiocb * __restrict acb, void *opt_data, size_t opt_dlen);
  436: /*
  437:  * schedAIORead() - Add AIO read task to scheduler queue
  438:  *
  439:  * @root = root task
  440:  * @func = task execution function
  441:  * @arg = 1st func argument
  442:  * @fd = file descriptor
  443:  * @buffer = Buffer
  444:  * @buflen = Buffer length
  445:  * @offset = Offset from start of file, if =-1 from current position
  446:  * return: NULL error or !=NULL new queued task
  447:  */
  448: inline sched_task_t *schedAIORead(sched_root_task_t * __restrict root, sched_task_func_t func, 
  449: 		void *arg, int fd, void *buffer, size_t buflen, off_t offset);
  450: /*
  451:  * schedAIOWrite() - Add AIO write task to scheduler queue
  452:  *
  453:  * @root = root task
  454:  * @func = task execution function
  455:  * @arg = 1st func argument
  456:  * @fd = file descriptor
  457:  * @buffer = Buffer
  458:  * @buflen = Buffer length
  459:  * @offset = Offset from start of file, if =-1 from current position
  460:  * return: NULL error or !=NULL new queued task
  461:  */
  462: inline sched_task_t *schedAIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func, 
  463: 		void *arg, int fd, void *buffer, size_t buflen, off_t offset);
  464: 
  465: /*
  466:  * schedLIO() - Add AIO bulk tasks to scheduler queue
  467:  *
  468:  * @root = root task
  469:  * @func = task execution function
  470:  * @arg = 1st func argument
  471:  * @acbs = AIO cb structure addresses
  472:  * @opt_data = Optional data
  473:  * @opt_dlen = Optional data length
  474:  * return: NULL error or !=NULL new queued task
  475:  */
  476: sched_task_t *schedLIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  477: 		struct aiocb ** __restrict acbs, void *opt_data, size_t opt_dlen);
  478: /*
  479:  * schedLIORead() - Add list of AIO read tasks to scheduler queue
  480:  *
  481:  * @root = root task
  482:  * @func = task execution function
  483:  * @arg = 1st func argument
  484:  * @fd = file descriptor
  485:  * @bufs = Buffer's list
  486:  * @nbufs = Number of Buffers
  487:  * @offset = Offset from start of file, if =-1 from current position
  488:  * return: NULL error or !=NULL new queued task
  489:  */
  490: inline sched_task_t *schedLIORead(sched_root_task_t * __restrict root, sched_task_func_t func, 
  491: 		void *arg, int fd, struct iovec *bufs, size_t nbufs, off_t offset);
  492: /*
  493:  * schedLIOWrite() - Add list of AIO write tasks to scheduler queue
  494:  *
  495:  * @root = root task
  496:  * @func = task execution function
  497:  * @arg = 1st func argument
  498:  * @fd = file descriptor
  499:  * @bufs = Buffer's list
  500:  * @nbufs = Number of Buffers
  501:  * @offset = Offset from start of file, if =-1 from current position
  502:  * return: NULL error or !=NULL new queued task
  503:  */
  504: inline sched_task_t *schedLIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func, 
  505: 		void *arg, int fd, struct iovec *bufs, size_t nbufs, off_t offset);
  506: #endif	/* EVFILT_LIO */
  507: 
  508: /*
  509:  * schedUser() - Add trigger USER task to scheduler queue
  510:  *
  511:  * @root = root task
  512:  * @func = task execution function
  513:  * @arg = 1st func argument
  514:  * @id = Trigger ID
  515:  * @opt_data = Optional data
  516:  * @opt_dlen = Optional user's trigger flags
  517:  * return: NULL error or !=NULL new queued task
  518:  */
  519: sched_task_t *schedUser(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  520: 		unsigned long id, void *opt_data, size_t opt_dlen);
  521: #define schedUserSelf(x)	schedUser(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  522: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  523: /*
  524:  * schedTrigger() - Triggering USER task
  525:  *
  526:  * @task = task
  527:  * return: -1 error or 0 ok
  528:  */
  529: int schedTrigger(sched_task_t * __restrict task);
  530: 
  531: /*
  532:  * schedTimer() - Add TIMER task to scheduler queue
  533:  *
  534:  * @root = root task
  535:  * @func = task execution function
  536:  * @arg = 1st func argument
  537:  * @ts = timeout argument structure
  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 *schedTimer(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  543: 		struct timespec ts, void *opt_data, size_t opt_dlen);
  544: #define schedTimerSelf(x)	schedTimer(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  545: 		TASK_TS((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  546: /*
  547:  * schedEvent() - Add EVENT task to scheduler queue
  548:  *
  549:  * @root = root task
  550:  * @func = task execution function
  551:  * @arg = 1st func argument
  552:  * @val = additional func argument
  553:  * @opt_data = Optional data
  554:  * @opt_dlen = Optional data length
  555:  * return: NULL error or !=NULL new queued task
  556:  */
  557: sched_task_t *schedEvent(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  558: 		unsigned long val, void *opt_data, size_t opt_dlen);
  559: #define schedEventSelf(x)	schedEvent(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  560: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  561: /*
  562:  * schedTask() - Add regular task to scheduler queue
  563:  *
  564:  * @root = root task
  565:  * @func = task execution function
  566:  * @arg = 1st func argument
  567:  * @prio = regular task priority, 0 is hi priority for regular tasks
  568:  * @opt_data = Optional data
  569:  * @opt_dlen = Optional data length
  570:  * return: NULL error or !=NULL new queued task
  571:  */
  572: sched_task_t *schedTask(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  573: 		unsigned long prio, void *opt_data, size_t opt_dlen);
  574: #define schedTaskSelf(x)	schedTask(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  575: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  576: /*
  577:  * schedSuspend() - Add Suspended task to scheduler queue
  578:  *
  579:  * @root = root task
  580:  * @func = task execution function
  581:  * @arg = 1st func argument
  582:  * @id = Trigger ID
  583:  * @opt_data = Optional data
  584:  * @opt_dlen = Optional user's trigger flags
  585:  * return: NULL error or !=NULL new queued task
  586:  */
  587: sched_task_t *schedSuspend(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  588: 		unsigned long id, void *opt_data, size_t opt_dlen);
  589: #define schedSuspendSelf(x)	schedUser(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  590: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  591: /*
  592:  * schedResumeby() - Resume suspended task
  593:  *
  594:  * @root = root task
  595:  * @criteria = find task by criteria 
  596:  * 	[CRITERIA_ANY|CRITERIA_ID|CRITERIA_DATA]
  597:  * @param = search parameter (sched_task_t *task| u_long id)
  598:  * return: -1 error or 0 resumed ok
  599:  */
  600: int schedResumeby(sched_root_task_t * __restrict root, unsigned char criteria, void *param);
  601: 
  602: /*
  603:  * schedCallOnce() - Call once from scheduler
  604:  *
  605:  * @root = root task
  606:  * @func = task execution function
  607:  * @arg = 1st func argument
  608:  * @val = additional func argument
  609:  * @opt_data = Optional data
  610:  * @opt_dlen = Optional data length
  611:  * return: return value from called func
  612:  */
  613: sched_task_t *schedCallOnce(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  614: 		unsigned long val, void *opt_data, size_t opt_dlen);
  615: #define schedCallAgain(x)	schedCallOnce(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  616: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  617: 
  618: 
  619: #endif

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