--- libaitsched/inc/aitsched.h 2012/01/24 21:59:46 1.5 +++ libaitsched/inc/aitsched.h 2012/03/13 10:01:59 1.6 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitsched.h,v 1.5 2012/01/24 21:59:46 misho Exp $ +* $Id: aitsched.h,v 1.6 2012/03/13 10:01:59 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 +Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -101,6 +101,8 @@ struct sched_HooksTask { sched_hook_func_t fetch; /* exception(sched_root_task_t *root, NULL) -> int */ sched_hook_func_t exception; + /* condition(sched_root_task_t *root, intptr_t *stopValue) -> int */ + sched_hook_func_t condition; } hook_exec; struct { /* init(sched_root_task_t *root, void *data) -> int */ @@ -162,6 +164,8 @@ struct sched_RootTask { int root_kq; struct timespec root_wait; struct timespec root_poll; + intptr_t root_cond; + pthread_mutex_t root_mtx[taskMAX]; sched_queue_t root_read; @@ -186,6 +190,7 @@ inline const char *sched_GetError(); /* * schedInit() - Init scheduler + * * @data = optional data if !=NULL * @datlen = data len if data is set * return: allocated root task if ok or NULL error @@ -194,18 +199,21 @@ sched_root_task_t *schedInit(void ** __restrict data, #define schedBegin() schedInit((void**) &schedRegisterHooks, 0) /* * schedEnd() - End scheduler & free all resources + * * @root = root task * return: -1 error or 0 ok */ int schedEnd(sched_root_task_t ** __restrict root); /* * schedRegisterHooks() - Register IO handles and bind tasks to it + * * @root = root task * return: -1 error or 0 ok */ int schedRegisterHooks(sched_root_task_t * __restrict root); /* * schedPolling() - Polling timeout period if no timer task is present + * * @root = root task * @ts = timeout polling period, if ==NULL INFINIT timeout * @tsold = old timeout polling if !=NULL @@ -214,19 +222,30 @@ int schedRegisterHooks(sched_root_task_t * __restrict inline int schedPolling(sched_root_task_t * __restrict root, struct timespec * __restrict ts, struct timespec * __restrict tsold); /* + * schedTermCondition() - Activate hook for scheduler condition kill + * + * @root = root task + * @condValue = condition value, kill schedRun() if condValue == killState + * return: -1 error ok 0 ok + */ +inline int schedTermCondition(sched_root_task_t * __restrict root, intptr_t condValue); +/* * schedCall() - Call task execution function + * * @task = current task * return: !=NULL error or =NULL ok */ inline void *schedCall(sched_task_t * __restrict task); /* * schedFetch() - Fetch ready task + * * @root = root task * return: =NULL error or !=NULL ready task */ inline void *schedFetch(sched_root_task_t * __restrict root); /* * schedRun() - Scheduler *run loop* + * * @root = root task * @killState = kill condition variable, if !=0 stop scheduler loop * return: -1 error or 0 ok @@ -234,12 +253,14 @@ inline void *schedFetch(sched_root_task_t * __restrict int schedRun(sched_root_task_t * __restrict root, volatile intptr_t * __restrict killState); /* * schedCancel() - Cancel task from scheduler + * * @task = task * return: -1 error or 0 ok */ int schedCancel(sched_task_t * __restrict task); /* * schedCancelby() - Cancel task from scheduler by criteria + * * @root = root task * @type = cancel from queue type, if =taskMAX cancel same task from all queues * @criteria = find task by criteria [CRITERIA_CALL|CRITERIA_ARG|CRITERIA_FD|CRITERIA_VAL|CRITERIA_TV] @@ -253,6 +274,7 @@ int schedCancelby(sched_root_task_t * __restrict root, /* * schedRead() - Add READ I/O task to scheduler queue + * * @root = root task * @func = task execution function * @arg = 1st func argument @@ -265,6 +287,7 @@ sched_task_t *schedRead(sched_root_task_t * __restrict int fd, void *opt_data, size_t opt_dlen); /* * schedWrite() - Add WRITE I/O task to scheduler queue + * * @root = root task * @func = task execution function * @arg = 1st func argument @@ -277,6 +300,7 @@ sched_task_t *schedWrite(sched_root_task_t * __restric int fd, void *opt_data, size_t opt_dlen); /* * schedTimer() - Add TIMER task to scheduler queue + * * @root = root task * @func = task execution function * @arg = 1st func argument @@ -289,6 +313,7 @@ sched_task_t *schedTimer(sched_root_task_t * __restric struct timespec ts, void *opt_data, size_t opt_dlen); /* * schedEvent() - Add EVENT task to scheduler queue + * * @root = root task * @func = task execution function * @arg = 1st func argument @@ -301,6 +326,7 @@ sched_task_t *schedEvent(sched_root_task_t * __restric unsigned long val, void *opt_data, size_t opt_dlen); /* * schedEventLo() - Add EVENT_Lo task to scheduler queue + * * @root = root task * @func = task execution function * @arg = 1st func argument @@ -313,6 +339,7 @@ sched_task_t *schedEventLo(sched_root_task_t * __restr unsigned long val, void *opt_data, size_t opt_dlen); /* * schedCallOnce() - Call once from scheduler + * * @root = root task * @func = task execution function * @arg = 1st func argument