File:  [ELWIX - Embedded LightWeight unIX -] / libaitsched / inc / aitsched.h
Revision 1.12: download - view: text, annotated - select for diffs - revision graph
Thu Aug 2 13:56:19 2012 UTC (11 years, 11 months ago) by misho
Branches: MAIN
CVS tags: sched2_7, SCHED2_6, HEAD
version 2.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.12 2012/08/02 13:56:19 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: 	taskEVENTLO,
   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: 		/* eventlo(sched_task_t *task, NULL) -> int */
  122: 		sched_hook_func_t	eventlo;
  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: 	struct timespec	root_wait;
  201: 	struct timespec	root_poll;
  202: 	intptr_t	root_cond;
  203: 	void		*root_ret;
  204: 
  205: 	pthread_mutex_t	root_mtx[taskMAX];
  206: 
  207: 	sched_queue_t	root_read;
  208: 	sched_queue_t	root_write;
  209: 	sched_queue_t	root_timer;
  210: 	sched_queue_t	root_alarm;
  211: 	sched_queue_t	root_node;
  212: 	sched_queue_t	root_proc;
  213: 	sched_queue_t	root_signal;
  214: 	sched_queue_t	root_aio;
  215: 	sched_queue_t	root_lio;
  216: 	sched_queue_t	root_user;
  217: 	sched_queue_t	root_event;
  218: 	sched_queue_t	root_eventlo;
  219: 	sched_queue_t	root_suspend;
  220: 	sched_queue_t	root_ready;
  221: 	sched_queue_t	root_unuse;
  222: 	int		root_eventlo_miss;
  223: 
  224: 	hooks_task_t	root_hooks;
  225: 	struct iovec	root_data;
  226: #define ROOT_DATA(x)	(x)->root_data.iov_base
  227: #define ROOT_DATLEN(x)	(x)->root_data.iov_len
  228: };
  229: #define ROOT_QUEUE_EMPTY(x, _q)	TAILQ_EMPTY(&((x)->root_##_q))
  230: #define ROOT_RETURN(x)	(x)->root_ret
  231: 
  232: 
  233: inline int sched_GetErrno();
  234: inline const char *sched_GetError();
  235: 
  236: 
  237: /*
  238:  * schedInit() - Init scheduler
  239:  *
  240:  * @data = optional data if !=NULL
  241:  * @datlen = data len if data is set
  242:  * return: allocated root task if ok or NULL error
  243:  */
  244: sched_root_task_t *schedInit(void ** __restrict data, size_t datlen);
  245: #define schedBegin()	schedInit((void**) &schedRegisterHooks, 0)
  246: /*
  247:  * schedEnd() - End scheduler & free all resources
  248:  *
  249:  * @root = root task
  250:  * return: -1 error or 0 ok
  251:  */
  252: int schedEnd(sched_root_task_t ** __restrict root);
  253: /*
  254:  * schedRegisterHooks() - Register IO handles and bind tasks to it
  255:  *
  256:  * @root = root task
  257:  * return: -1 error or 0 ok
  258:  */
  259: int schedRegisterHooks(sched_root_task_t * __restrict root);
  260: /*
  261:  * schedPolling() - Polling timeout period if no timer task is present
  262:  *
  263:  * @root = root task
  264:  * @ts = timeout polling period, if ==NULL INFINIT timeout
  265:  * @tsold = old timeout polling if !=NULL
  266:  * return: -1 error or 0 ok
  267:  */
  268: inline int schedPolling(sched_root_task_t * __restrict root, 
  269: 		struct timespec * __restrict ts, struct timespec * __restrict tsold);
  270: /*
  271:  * schedTermCondition() - Activate hook for scheduler condition kill
  272:  *
  273:  * @root = root task
  274:  * @condValue = condition value, kill schedRun() if condValue == killState
  275:  * return: -1 error ok 0 ok
  276:  */
  277: inline int schedTermCondition(sched_root_task_t * __restrict root, intptr_t condValue);
  278: /*
  279:  * schedCall() - Call task execution function
  280:  *
  281:  * @task = current task
  282:  * return: !=NULL error or =NULL ok
  283:  */
  284: inline void *schedCall(sched_task_t * __restrict task);
  285: /*
  286:  * schedFetch() - Fetch ready task
  287:  *
  288:  * @root = root task
  289:  * return: =NULL error or !=NULL ready task
  290:  */
  291: inline void *schedFetch(sched_root_task_t * __restrict root);
  292: /*
  293:  * schedRun() - Scheduler *run loop*
  294:  *
  295:  * @root = root task
  296:  * @killState = kill condition variable, if !=0 stop scheduler loop
  297:  * return: -1 error or 0 ok
  298:  */
  299: int schedRun(sched_root_task_t *root, volatile intptr_t * __restrict killState);
  300: /*
  301:  * schedCancel() - Cancel task from scheduler
  302:  *
  303:  * @task = task
  304:  * return: -1 error or 0 ok
  305:  */
  306: int schedCancel(sched_task_t * __restrict task);
  307: /*
  308:  * schedCancelby() - Cancel task from scheduler by criteria
  309:  *
  310:  * @root = root task
  311:  * @type = cancel from queue type, if =taskMAX cancel same task from all queues
  312:  * @criteria = find task by criteria 
  313:  * 	[CRITERIA_ANY|CRITERIA_CALL|CRITERIA_ARG|CRITERIA_FD|CRITERIA_VAL|CRITERIA_ID|CRITERIA_TS|CRITERIA_DATA]
  314:  * @param = search parameter
  315:  * @hook = custom cleanup hook function, may be NULL
  316:  * return: -1 error, -2 error in sub-stage cancel execution, -3 error from custom hook or 0 ok
  317:  */
  318: int schedCancelby(sched_root_task_t * __restrict root, sched_task_type_t type, 
  319: 		u_char criteria, void *param, sched_hook_func_t hook);
  320: 
  321: 
  322: /*
  323:  * schedRead() - Add READ I/O task to scheduler queue
  324:  *
  325:  * @root = root task
  326:  * @func = task execution function
  327:  * @arg = 1st func argument
  328:  * @fd = fd handle
  329:  * @opt_data = Optional data
  330:  * @opt_dlen = Optional data length
  331:  * return: NULL error or !=NULL new queued task
  332:  */
  333: sched_task_t *schedRead(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  334: 		int fd, void *opt_data, size_t opt_dlen);
  335: #define schedReadSelf(x)	schedRead(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  336: 		TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  337: /*
  338:  * schedWrite() - Add WRITE I/O task to scheduler queue
  339:  *
  340:  * @root = root task
  341:  * @func = task execution function
  342:  * @arg = 1st func argument
  343:  * @fd = fd handle
  344:  * @opt_data = Optional data
  345:  * @opt_dlen = Optional data length
  346:  * return: NULL error or !=NULL new queued task
  347:  */
  348: sched_task_t *schedWrite(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  349: 		int fd, void *opt_data, size_t opt_dlen);
  350: #define schedWriteSelf(x)	schedWrite(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  351: 		TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  352: /*
  353:  * schedAlarm() - Add ALARM task to scheduler queue
  354:  *
  355:  * @root = root task
  356:  * @func = task execution function
  357:  * @arg = 1st func argument
  358:  * @ts = timeout argument structure, minimum alarm timer resolution is 1msec!
  359:  * @opt_data = Optional data
  360:  * @opt_dlen = Optional data length
  361:  * return: NULL error or !=NULL new queued task
  362:  */
  363: sched_task_t *schedAlarm(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  364: 		struct timespec ts, void *opt_data, size_t opt_dlen);
  365: #define schedAlarmSelf(x)	schedAlarm(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  366: 		TASK_TS((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  367: /*
  368:  * schedNode() - Add NODE task to scheduler queue
  369:  *
  370:  * @root = root task
  371:  * @func = task execution function
  372:  * @arg = 1st func argument
  373:  * @fd = fd handle
  374:  * @opt_data = Optional data
  375:  * @opt_dlen = Optional data length
  376:  * return: NULL error or !=NULL new queued task
  377:  */
  378: sched_task_t *schedNode(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  379: 		int fd, void *opt_data, size_t opt_dlen);
  380: #define schedNodeSelf(x)	schedNode(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  381: 		TASK_FD((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  382: /*
  383:  * schedProc() - Add PROC task to scheduler queue
  384:  *
  385:  * @root = root task
  386:  * @func = task execution function
  387:  * @arg = 1st func argument
  388:  * @pid = PID
  389:  * @opt_data = Optional data
  390:  * @opt_dlen = Optional data length
  391:  * return: NULL error or !=NULL new queued task
  392:  */
  393: sched_task_t *schedProc(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  394: 		unsigned long pid, void *opt_data, size_t opt_dlen);
  395: #define schedProcSelf(x)	schedProc(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  396: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  397: /*
  398:  * schedSignal() - Add SIGNAL task to scheduler queue
  399:  *
  400:  * @root = root task
  401:  * @func = task execution function
  402:  * @arg = 1st func argument
  403:  * @sig = Signal
  404:  * @opt_data = Optional data
  405:  * @opt_dlen = Optional data length
  406:  * return: NULL error or !=NULL new queued task
  407:  */
  408: sched_task_t *schedSignal(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  409: 		unsigned long sig, void *opt_data, size_t opt_dlen);
  410: #define schedSignalSelf(x)	schedSignal(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  411: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  412: 
  413: #ifdef EVFILT_LIO
  414: /*
  415:  * schedAIO() - Add AIO task to scheduler queue
  416:  *
  417:  * @root = root task
  418:  * @func = task execution function
  419:  * @arg = 1st func argument
  420:  * @acb = AIO cb structure address
  421:  * @opt_data = Optional data
  422:  * @opt_dlen = Optional data length
  423:  * return: NULL error or !=NULL new queued task
  424:  */
  425: sched_task_t *schedAIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  426: 		struct aiocb * __restrict acb, void *opt_data, size_t opt_dlen);
  427: /*
  428:  * schedAIORead() - Add AIO read task to scheduler queue
  429:  *
  430:  * @root = root task
  431:  * @func = task execution function
  432:  * @arg = 1st func argument
  433:  * @fd = file descriptor
  434:  * @buffer = Buffer
  435:  * @buflen = Buffer length
  436:  * @offset = Offset from start of file, if =-1 from current position
  437:  * return: NULL error or !=NULL new queued task
  438:  */
  439: inline sched_task_t *schedAIORead(sched_root_task_t * __restrict root, sched_task_func_t func, 
  440: 		void *arg, int fd, void *buffer, size_t buflen, off_t offset);
  441: /*
  442:  * schedAIOWrite() - Add AIO write task to scheduler queue
  443:  *
  444:  * @root = root task
  445:  * @func = task execution function
  446:  * @arg = 1st func argument
  447:  * @fd = file descriptor
  448:  * @buffer = Buffer
  449:  * @buflen = Buffer length
  450:  * @offset = Offset from start of file, if =-1 from current position
  451:  * return: NULL error or !=NULL new queued task
  452:  */
  453: inline sched_task_t *schedAIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func, 
  454: 		void *arg, int fd, void *buffer, size_t buflen, off_t offset);
  455: 
  456: /*
  457:  * schedLIO() - Add AIO bulk tasks to scheduler queue
  458:  *
  459:  * @root = root task
  460:  * @func = task execution function
  461:  * @arg = 1st func argument
  462:  * @acbs = AIO cb structure addresses
  463:  * @opt_data = Optional data
  464:  * @opt_dlen = Optional data length
  465:  * return: NULL error or !=NULL new queued task
  466:  */
  467: sched_task_t *schedLIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  468: 		struct aiocb ** __restrict acbs, void *opt_data, size_t opt_dlen);
  469: /*
  470:  * schedLIORead() - Add list of AIO read tasks to scheduler queue
  471:  *
  472:  * @root = root task
  473:  * @func = task execution function
  474:  * @arg = 1st func argument
  475:  * @fd = file descriptor
  476:  * @bufs = Buffer's list
  477:  * @nbufs = Number of Buffers
  478:  * @offset = Offset from start of file, if =-1 from current position
  479:  * return: NULL error or !=NULL new queued task
  480:  */
  481: inline sched_task_t *schedLIORead(sched_root_task_t * __restrict root, sched_task_func_t func, 
  482: 		void *arg, int fd, struct iovec *bufs, size_t nbufs, off_t offset);
  483: /*
  484:  * schedLIOWrite() - Add list of AIO write tasks to scheduler queue
  485:  *
  486:  * @root = root task
  487:  * @func = task execution function
  488:  * @arg = 1st func argument
  489:  * @fd = file descriptor
  490:  * @bufs = Buffer's list
  491:  * @nbufs = Number of Buffers
  492:  * @offset = Offset from start of file, if =-1 from current position
  493:  * return: NULL error or !=NULL new queued task
  494:  */
  495: inline sched_task_t *schedLIOWrite(sched_root_task_t * __restrict root, sched_task_func_t func, 
  496: 		void *arg, int fd, struct iovec *bufs, size_t nbufs, off_t offset);
  497: #endif	/* EVFILT_LIO */
  498: 
  499: /*
  500:  * schedUser() - Add trigger USER task to scheduler queue
  501:  *
  502:  * @root = root task
  503:  * @func = task execution function
  504:  * @arg = 1st func argument
  505:  * @id = Trigger ID
  506:  * @opt_data = Optional data
  507:  * @opt_dlen = Optional user's trigger flags
  508:  * return: NULL error or !=NULL new queued task
  509:  */
  510: sched_task_t *schedUser(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  511: 		unsigned long id, void *opt_data, size_t opt_dlen);
  512: #define schedUserSelf(x)	schedUser(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  513: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  514: /*
  515:  * schedTrigger() - Triggering USER task
  516:  *
  517:  * @task = task
  518:  * return: -1 error or 0 ok
  519:  */
  520: int schedTrigger(sched_task_t * __restrict task);
  521: 
  522: /*
  523:  * schedTimer() - Add TIMER task to scheduler queue
  524:  *
  525:  * @root = root task
  526:  * @func = task execution function
  527:  * @arg = 1st func argument
  528:  * @ts = timeout argument structure
  529:  * @opt_data = Optional data
  530:  * @opt_dlen = Optional data length
  531:  * return: NULL error or !=NULL new queued task
  532:  */
  533: sched_task_t *schedTimer(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  534: 		struct timespec ts, void *opt_data, size_t opt_dlen);
  535: #define schedTimerSelf(x)	schedTimer(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  536: 		TASK_TS((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  537: /*
  538:  * schedEvent() - Add EVENT task to scheduler queue
  539:  *
  540:  * @root = root task
  541:  * @func = task execution function
  542:  * @arg = 1st func argument
  543:  * @val = additional func argument
  544:  * @opt_data = Optional data
  545:  * @opt_dlen = Optional data length
  546:  * return: NULL error or !=NULL new queued task
  547:  */
  548: sched_task_t *schedEvent(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  549: 		unsigned long val, void *opt_data, size_t opt_dlen);
  550: #define schedEventSelf(x)	schedEvent(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  551: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  552: /*
  553:  * schedEventLo() - Add EVENT_Lo task to scheduler queue
  554:  *
  555:  * @root = root task
  556:  * @func = task execution function
  557:  * @arg = 1st func argument
  558:  * @val = additional func argument
  559:  * @opt_data = Optional data
  560:  * @opt_dlen = Optional data length
  561:  * return: NULL error or !=NULL new queued task
  562:  */
  563: sched_task_t *schedEventLo(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  564: 		unsigned long val, void *opt_data, size_t opt_dlen);
  565: #define schedEventLoSelf(x)	schedEventLo(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  566: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  567: /*
  568:  * schedSuspend() - Add Suspended task to scheduler queue
  569:  *
  570:  * @root = root task
  571:  * @func = task execution function
  572:  * @arg = 1st func argument
  573:  * @id = Trigger ID
  574:  * @opt_data = Optional data
  575:  * @opt_dlen = Optional user's trigger flags
  576:  * return: NULL error or !=NULL new queued task
  577:  */
  578: sched_task_t *schedSuspend(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  579: 		unsigned long id, void *opt_data, size_t opt_dlen);
  580: #define schedSuspendSelf(x)	schedUser(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  581: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  582: /*
  583:  * schedResumeby() - Resume suspended task
  584:  *
  585:  * @root = root task
  586:  * @criteria = find task by criteria 
  587:  * 	[CRITERIA_ANY|CRITERIA_ID|CRITERIA_DATA]
  588:  * @param = search parameter (sched_task_t *task| u_long id)
  589:  * return: -1 error or 0 resumed ok
  590:  */
  591: int schedResumeby(sched_root_task_t * __restrict root, unsigned char criteria, void *param);
  592: 
  593: /*
  594:  * schedCallOnce() - Call once from scheduler
  595:  *
  596:  * @root = root task
  597:  * @func = task execution function
  598:  * @arg = 1st func argument
  599:  * @val = additional func argument
  600:  * @opt_data = Optional data
  601:  * @opt_dlen = Optional data length
  602:  * return: return value from called func
  603:  */
  604: sched_task_t *schedCallOnce(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, 
  605: 		unsigned long val, void *opt_data, size_t opt_dlen);
  606: #define schedCallAgain(x)	schedCallOnce(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \
  607: 		TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x)))
  608: 
  609: 
  610: #endif

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