--- libaitsched/src/aitsched.c 2012/01/24 21:59:47 1.5 +++ libaitsched/src/aitsched.c 2012/03/13 10:00:37 1.5.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitsched.c,v 1.5 2012/01/24 21:59:47 misho Exp $ +* $Id: aitsched.c,v 1.5.2.1 2012/03/13 10:00:37 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 @@ -86,6 +86,7 @@ sched_SetErr(int eno, char *estr, ...) /* * schedRegisterHooks() - Register IO handles and bind tasks to it + * * @root = root task * return: -1 error or 0 ok */ @@ -113,6 +114,7 @@ schedRegisterHooks(sched_root_task_t * __restrict root /* * schedInit() - Init scheduler + * * @data = optional data if !=NULL * @datlen = data len if data is set * return: allocated root task if ok or NULL error @@ -182,6 +184,7 @@ schedInit(void ** __restrict data, size_t datlen) /* * schedEnd() - End scheduler & free all resources + * * @root = root task * return: -1 error or 0 ok */ @@ -241,6 +244,7 @@ schedEnd(sched_root_task_t ** __restrict root) /* * schedCall() - Call task execution function + * * @task = current task * return: !=NULL error or =NULL ok */ @@ -264,6 +268,7 @@ schedCall(sched_task_t * __restrict task) /* * schedFetch() - Fetch ready task + * * @root = root task * return: =NULL error or !=NULL ready task */ @@ -285,6 +290,7 @@ schedFetch(sched_root_task_t * __restrict root) /* * schedCancel() - Cancel task from scheduler + * * @task = task * return: -1 error or 0 ok */ @@ -339,6 +345,7 @@ 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] @@ -458,6 +465,7 @@ schedCancelby(sched_root_task_t * __restrict root, sch /* * schedRun() - Scheduler *run loop* + * * @root = root task * @killState = kill condition variable, if !=0 stop scheduler loop * return: -1 error or 0 ok @@ -474,12 +482,18 @@ schedRun(sched_root_task_t * __restrict root, volatile if (root->root_hooks.hook_exec.run(root, NULL)) return -1; if (root->root_hooks.hook_exec.fetch) { - if (killState) - while (!*killState) { - if ((task = root->root_hooks.hook_exec.fetch(root, NULL))) - schedCall(task); - } - else + if (killState) { + if (root->root_hooks.hook_exec.condition) + while (root->root_hooks.hook_exec.condition(root, (void*) killState)) { + if ((task = root->root_hooks.hook_exec.fetch(root, NULL))) + schedCall(task); + } + else + while (!*killState) { + if ((task = root->root_hooks.hook_exec.fetch(root, NULL))) + schedCall(task); + } + } else while ((task = root->root_hooks.hook_exec.fetch(root, NULL))) schedCall(task); } @@ -489,6 +503,7 @@ schedRun(sched_root_task_t * __restrict root, volatile /* * 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 @@ -509,5 +524,23 @@ schedPolling(sched_root_task_t * __restrict root, stru else root->root_poll = *ts; + return 0; +} + +/* + * 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) +{ + if (!root) + return -1; + + root->root_cond = condValue; + root->root_hooks.hook_exec.condition = sched_hook_condition; return 0; }