version 1.6.2.4, 2012/05/03 15:05:09
|
version 1.7.2.1, 2012/05/15 15:47:12
|
Line 190 schedInit(void ** __restrict data, size_t datlen)
|
Line 190 schedInit(void ** __restrict data, size_t datlen)
|
int |
int |
schedEnd(sched_root_task_t ** __restrict root) |
schedEnd(sched_root_task_t ** __restrict root) |
{ |
{ |
sched_task_t *task; | sched_task_t *task, *tmp; |
#ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
register int i; |
register int i; |
#endif |
#endif |
Line 198 schedEnd(sched_root_task_t ** __restrict root)
|
Line 198 schedEnd(sched_root_task_t ** __restrict root)
|
if (!root || !*root) |
if (!root || !*root) |
return -1; |
return -1; |
|
|
TAILQ_FOREACH(task, &(*root)->root_read, task_node) { | TAILQ_FOREACH_SAFE(task, &(*root)->root_read, task_node, tmp) { |
schedCancel(task); |
schedCancel(task); |
} |
} |
TAILQ_FOREACH(task, &(*root)->root_write, task_node) { | TAILQ_FOREACH_SAFE(task, &(*root)->root_write, task_node, tmp) { |
schedCancel(task); |
schedCancel(task); |
} |
} |
TAILQ_FOREACH(task, &(*root)->root_timer, task_node) { | TAILQ_FOREACH_SAFE(task, &(*root)->root_timer, task_node, tmp) { |
schedCancel(task); |
schedCancel(task); |
} |
} |
TAILQ_FOREACH(task, &(*root)->root_event, task_node) { | TAILQ_FOREACH_SAFE(task, &(*root)->root_event, task_node, tmp) { |
schedCancel(task); |
schedCancel(task); |
} |
} |
TAILQ_FOREACH(task, &(*root)->root_eventlo, task_node) { | TAILQ_FOREACH_SAFE(task, &(*root)->root_eventlo, task_node, tmp) { |
schedCancel(task); |
schedCancel(task); |
} |
} |
TAILQ_FOREACH(task, &(*root)->root_ready, task_node) { | TAILQ_FOREACH_SAFE(task, &(*root)->root_ready, task_node, tmp) { |
schedCancel(task); |
schedCancel(task); |
} |
} |
|
|
Line 347 schedCancel(sched_task_t * __restrict task)
|
Line 347 schedCancel(sched_task_t * __restrict task)
|
* |
* |
* @root = root task |
* @root = root task |
* @type = cancel from queue type, if =taskMAX cancel same task from all queues |
* @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] | * @criteria = find task by criteria [CRITERIA_CALL|CRITERIA_ARG|CRITERIA_FD|CRITERIA_VAL|CRITERIA_TS] |
* @param = search parameter |
* @param = search parameter |
* @hook = custom cleanup hook function, may be NULL |
* @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 |
* return: -1 error, -2 error in sub-stage cancel execution, -3 error from custom hook or 0 ok |
Line 356 int
|
Line 356 int
|
schedCancelby(sched_root_task_t * __restrict root, sched_task_type_t type, |
schedCancelby(sched_root_task_t * __restrict root, sched_task_type_t type, |
u_char criteria, void *param, sched_hook_func_t hook) |
u_char criteria, void *param, sched_hook_func_t hook) |
{ |
{ |
sched_task_t *task; | sched_task_t *task, *tmp; |
sched_queue_t *queue; |
sched_queue_t *queue; |
int flg = 0; | register int flg = 0; |
|
|
if (!root) |
if (!root) |
return -1; |
return -1; |
Line 403 schedCancelby(sched_root_task_t * __restrict root, sch
|
Line 403 schedCancelby(sched_root_task_t * __restrict root, sch
|
#ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
pthread_mutex_lock(&root->root_mtx[type]); |
pthread_mutex_lock(&root->root_mtx[type]); |
#endif |
#endif |
TAILQ_FOREACH(task, queue, task_node) | TAILQ_FOREACH_SAFE(task, queue, task_node, tmp) { |
if (criteria == CRITERIA_CALL) { | flg ^= flg; |
if (task->task_func == (sched_task_func_t) param) { | switch (criteria) { |
flg++; | case CRITERIA_CALL: |
| if (TASK_FUNC(task) == (sched_task_func_t) param) |
| flg = 1; |
break; |
break; |
} | case CRITERIA_ARG: |
} else if (criteria == CRITERIA_ARG) { | if (TASK_ARG(task) == param) |
if (task->task_arg == param) { | flg = 1; |
flg++; | |
break; |
break; |
} | case CRITERIA_FD: |
} else if (criteria == CRITERIA_FD) { | if (TASK_FD(task) == (intptr_t) param) |
if (TASK_FD(task) == (intptr_t) param) { | flg = 1; |
flg++; | |
break; |
break; |
} | case CRITERIA_VAL: |
} else if (criteria == CRITERIA_VAL) { | if (TASK_VAL(task) == (u_long) param) |
if (TASK_VAL(task) == (u_long) param) { | flg = 1; |
flg++; | |
break; |
break; |
} | case CRITERIA_TS: |
} else if (criteria == CRITERIA_TV) { | if (!sched_timespeccmp(&TASK_TS(task), (struct timespec*) param, -)) |
if (!sched_timespeccmp(&TASK_TS(task), (struct timespec*) param, -)) { | flg = 1; |
flg++; | |
break; |
break; |
} | default: |
} else { | sched_SetErr(EINVAL, "Invalid parameter criteria %d", criteria); |
#ifdef HAVE_LIBPTHREAD | flg = -1; |
pthread_mutex_unlock(&root->root_mtx[type]); | |
#endif | |
sched_SetErr(EINVAL, "Invalid parameter criteria %d", criteria); | |
return -1; | |
} |
} |
#ifdef HAVE_LIBPTHREAD | if (flg < 0) |
pthread_mutex_unlock(&root->root_mtx[type]); | break; |
#endif | /* cancel choosen task */ |
if (!flg || !task) /* task not found */ | if (flg > 0) { |
return 0; | if (TASK_ROOT(task)->root_hooks.hook_exec.cancel) |
| if (TASK_ROOT(task)->root_hooks.hook_exec.cancel(task, NULL)) { |
| flg = -1; |
| break; |
| } |
| /* custom hook */ |
| if (hook) |
| if (hook(task, NULL)) { |
| flg = -3; |
| break; |
| } |
|
|
if (TASK_ROOT(task)->root_hooks.hook_exec.cancel) | TAILQ_REMOVE(queue, task, task_node); |
if (TASK_ROOT(task)->root_hooks.hook_exec.cancel(task, NULL)) | if (TASK_TYPE(task) != taskUNUSE) |
return -1; | _sched_unuseTask(task); |
if (hook) | |
if (hook(task, NULL)) | |
return -3; | |
|
|
|
flg ^= flg; /* ok */ |
|
} |
|
} |
#ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
pthread_mutex_lock(&TASK_ROOT(task)->root_mtx[type]); | pthread_mutex_unlock(&root->root_mtx[type]); |
#endif |
#endif |
TAILQ_REMOVE(queue, task, task_node); | return flg; |
#ifdef HAVE_LIBPTHREAD | |
pthread_mutex_unlock(&TASK_ROOT(task)->root_mtx[type]); | |
#endif | |
| |
if (TASK_TYPE(task) != taskUNUSE) | |
_sched_unuseTask(task); | |
return 0; | |
} |
} |
|
|
/* |
/* |