--- libaitsched/inc/aitsched.h 2012/05/31 14:17:58 1.9.2.1 +++ libaitsched/inc/aitsched.h 2012/07/30 00:20:26 1.11.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitsched.h,v 1.9.2.1 2012/05/31 14:17:58 misho Exp $ +* $Id: aitsched.h,v 1.11.2.1 2012/07/30 00:20:26 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -55,12 +55,14 @@ SUCH DAMAGE. /* criteria type */ -#define CRITERIA_CALL 0 -#define CRITERIA_ARG 1 -#define CRITERIA_FD 2 -#define CRITERIA_VAL 3 -#define CRITERIA_TS 4 -#define CRITERIA_DATA 5 +#define CRITERIA_ANY 0 +#define CRITERIA_CALL 1 +#define CRITERIA_ARG 2 +#define CRITERIA_FD 3 +#define CRITERIA_VAL 4 +#define CRITERIA_TS 5 +#define CRITERIA_DATA 6 +#define CRITERIA_ID 7 /* early declaration for root & task */ @@ -78,6 +80,7 @@ typedef enum { taskSIGNAL, taskEVENT, taskEVENTLO, + taskSUSPEND, taskREADY, taskUNUSE, taskMAX @@ -107,10 +110,14 @@ struct sched_HooksTask { sched_hook_func_t event; /* eventlo(sched_task_t *task, NULL) -> int */ sched_hook_func_t eventlo; + /* suspend(sched_task_t *task, NULL) -> int */ + sched_hook_func_t suspend; } hook_add; struct { /* cancel(sched_task_t *task, NULL) -> int */ sched_hook_func_t cancel; + /* resume(sched_task_t *task, NULL) -> int */ + sched_hook_func_t resume; /* run(sched_root_task_t *root, NULL) -> int */ sched_hook_func_t run; /* fetch(sched_root_task_t *root, NULL) -> sched_task_t* */ @@ -135,14 +142,15 @@ typedef struct sched_HooksTask hooks_task_t; typedef void *(*sched_task_func_t)(sched_task_t * /* current task data*/); /* task lock helpers */ -#define TASK_LOCK(x) ((x)->task_lock++) +#define TASK_LOCK(x) ((x)->task_lock = 42) #define TASK_UNLOCK(x) ((x)->task_lock ^= (x)->task_lock) #define TASK_ISLOCKED(x) ((x)->task_lock) /* task & queue */ struct sched_Task { volatile int task_lock; - unsigned int task_id; + uintptr_t task_id; +#define TASK_ID(x) ((struct sched_Task*) (x)->task_id) sched_task_type_t task_type; #define TASK_TYPE(x) (x)->task_type @@ -182,6 +190,7 @@ struct sched_RootTask { struct timespec root_wait; struct timespec root_poll; intptr_t root_cond; + void *root_ret; pthread_mutex_t root_mtx[taskMAX]; @@ -195,6 +204,7 @@ struct sched_RootTask { sched_queue_t root_signal; sched_queue_t root_event; sched_queue_t root_eventlo; + sched_queue_t root_suspend; sched_queue_t root_ready; sched_queue_t root_unuse; int root_eventlo_miss; @@ -205,6 +215,7 @@ struct sched_RootTask { #define ROOT_DATLEN(x) (x)->root_data.iov_len }; #define ROOT_QUEUE_EMPTY(x, _q) TAILQ_EMPTY(&((x)->root_##_q)) +#define ROOT_RETURN(x) (x)->root_ret inline int sched_GetErrno(); @@ -286,7 +297,8 @@ int schedCancel(sched_task_t * __restrict task); * * @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_TS|CRITERIA_DATA] + * @criteria = find task by criteria + * [CRITERIA_ANY|CRITERIA_CALL|CRITERIA_ARG|CRITERIA_FD|CRITERIA_VAL|CRITERIA_ID|CRITERIA_TS|CRITERIA_DATA] * @param = search parameter * @hook = custom cleanup hook function, may be NULL * return: -1 error, -2 error in sub-stage cancel execution, -3 error from custom hook or 0 ok @@ -394,7 +406,7 @@ sched_task_t *schedSignal(sched_root_task_t * __restri * @arg = 1st func argument * @id = Trigger ID * @opt_data = Optional data - * @opt_dlen = Optional data length + * @opt_dlen = Optional user's trigger flags * return: NULL error or !=NULL new queued task */ sched_task_t *schedUser(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, @@ -454,6 +466,31 @@ sched_task_t *schedEventLo(sched_root_task_t * __restr unsigned long val, void *opt_data, size_t opt_dlen); #define schedEventLoSelf(x) schedEventLo(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \ TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x))) +/* + * schedSuspend() - Add Suspended task to scheduler queue + * + * @root = root task + * @func = task execution function + * @arg = 1st func argument + * @id = Trigger ID + * @opt_data = Optional data + * @opt_dlen = Optional user's trigger flags + * return: NULL error or !=NULL new queued task + */ +sched_task_t *schedSuspend(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, + unsigned long id, void *opt_data, size_t opt_dlen); +#define schedSuspendSelf(x) schedUser(TASK_ROOT((x)), TASK_FUNC((x)), TASK_ARG((x)), \ + TASK_VAL((x)), TASK_DATA((x)), TASK_DATLEN((x))) +/* + * schedResumeby() - Resume suspended task + * + * @root = root task + * @criteria = find task by criteria + * [CRITERIA_ANY|CRITERIA_ID|CRITERIA_DATA] + * @param = search parameter (sched_task_t *task| u_long id) + * return: -1 error or 0 resumed ok + */ +int schedResumeby(sched_root_task_t * __restrict root, unsigned char criteria, void *param); /* * schedCallOnce() - Call once from scheduler