version 1.11, 2012/08/02 13:56:19
|
version 1.12.4.1, 2012/08/21 11:07:16
|
Line 979 schedEvent(sched_root_task_t * __restrict root, sched_
|
Line 979 schedEvent(sched_root_task_t * __restrict root, sched_
|
|
|
|
|
/* |
/* |
* schedEventLo() - Add EVENT_Lo task to scheduler queue | * schedTask() - Add regular task to scheduler queue |
* |
* |
* @root = root task |
* @root = root task |
* @func = task execution function |
* @func = task execution function |
* @arg = 1st func argument |
* @arg = 1st func argument |
* @val = additional func argument | * @prio = regular task priority, 0 is hi priority for regular tasks |
* @opt_data = Optional data |
* @opt_data = Optional data |
* @opt_dlen = Optional data length |
* @opt_dlen = Optional data length |
* return: NULL error or !=NULL new queued task |
* return: NULL error or !=NULL new queued task |
*/ |
*/ |
sched_task_t * |
sched_task_t * |
schedEventLo(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, u_long val, | schedTask(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, u_long prio, |
void *opt_data, size_t opt_dlen) |
void *opt_data, size_t opt_dlen) |
{ |
{ |
sched_task_t *task; | sched_task_t *task, *tmp, *t = NULL; |
void *ptr; |
void *ptr; |
|
|
if (!root || !func) |
if (!root || !func) |
Line 1004 schedEventLo(sched_root_task_t * __restrict root, sche
|
Line 1004 schedEventLo(sched_root_task_t * __restrict root, sche
|
return NULL; |
return NULL; |
|
|
task->task_func = func; |
task->task_func = func; |
TASK_TYPE(task) = taskEVENT; | TASK_TYPE(task) = taskTASK; |
TASK_ROOT(task) = root; |
TASK_ROOT(task) = root; |
|
|
TASK_ARG(task) = arg; |
TASK_ARG(task) = arg; |
TASK_VAL(task) = val; | TASK_VAL(task) = prio; |
|
|
TASK_DATA(task) = opt_data; |
TASK_DATA(task) = opt_data; |
TASK_DATLEN(task) = opt_dlen; |
TASK_DATLEN(task) = opt_dlen; |
|
|
if (root->root_hooks.hook_add.eventlo) | if (root->root_hooks.hook_add.task) |
ptr = root->root_hooks.hook_add.eventlo(task, NULL); | ptr = root->root_hooks.hook_add.task(task, NULL); |
else |
else |
ptr = NULL; |
ptr = NULL; |
|
|
if (!ptr) { |
if (!ptr) { |
#ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
pthread_mutex_lock(&root->root_mtx[taskEVENTLO]); | pthread_mutex_lock(&root->root_mtx[taskTASK]); |
#endif |
#endif |
TAILQ_INSERT_TAIL(&root->root_eventlo, TASK_ID(task), task_node); | TAILQ_FOREACH_SAFE(t, &root->root_task, task_node, tmp) |
| if (TASK_VAL(task) < TASK_VAL(t)) |
| break; |
| if (!t) |
| TAILQ_INSERT_TAIL(&root->root_task, TASK_ID(task), task_node); |
| else |
| TAILQ_INSERT_BEFORE(t, TASK_ID(task), task_node); |
#ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
pthread_mutex_unlock(&root->root_mtx[taskEVENTLO]); | pthread_mutex_unlock(&root->root_mtx[taskTASK]); |
#endif |
#endif |
} else |
} else |
task = _sched_unuseTask(task); |
task = _sched_unuseTask(task); |
Line 1126 schedCallOnce(sched_root_task_t * __restrict root, sch
|
Line 1132 schedCallOnce(sched_root_task_t * __restrict root, sch
|
_sched_unuseTask(task); |
_sched_unuseTask(task); |
return ret; |
return ret; |
} |
} |
|
|
|
/* |
|
* schedThread() - Add thread task to scheduler queue |
|
* |
|
* @root = root task |
|
* @func = task execution function |
|
* @arg = 1st func argument |
|
* @detach = Detach thread from scheduler, if !=0 |
|
* @opt_data = Optional data |
|
* @opt_dlen = Optional data length |
|
* return: NULL error or !=NULL new queued task |
|
*/ |
|
sched_task_t * |
|
schedThread(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, int detach, |
|
void *opt_data, size_t opt_dlen) |
|
{ |
|
#ifndef HAVE_LIBPTHREAD |
|
sched_SetErr(ENOTSUP, "Not supported thread tasks"); |
|
return NULL; |
|
#endif |
|
sched_task_t *task; |
|
void *ptr; |
|
pthread_t tid; |
|
pthread_attr_t attr; |
|
|
|
if (!root || !func) |
|
return NULL; |
|
|
|
/* get new task */ |
|
if (!(task = _sched_useTask(root))) |
|
return NULL; |
|
|
|
task->task_func = func; |
|
TASK_TYPE(task) = taskTHREAD; |
|
TASK_ROOT(task) = root; |
|
|
|
TASK_ARG(task) = arg; |
|
|
|
TASK_DATA(task) = opt_data; |
|
TASK_DATLEN(task) = opt_dlen; |
|
|
|
if (root->root_hooks.hook_add.thread) |
|
ptr = root->root_hooks.hook_add.thread(task, NULL); |
|
else |
|
ptr = NULL; |
|
|
|
if (!ptr) { |
|
pthread_mutex_lock(&root->root_mtx[taskTHREAD]); |
|
TAILQ_INSERT_TAIL(&root->root_thread, TASK_ID(task), task_node); |
|
pthread_mutex_unlock(&root->root_mtx[taskTHREAD]); |
|
|
|
pthread_attr_init(&attr); |
|
pthread_attr_setdetachstate(&attr, detach ? |
|
PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE); |
|
if (pthread_create(&tid, &attr, |
|
(void *(*)(void*)) task->task_func, task)) { |
|
LOGERR; |
|
pthread_mutex_lock(&root->root_mtx[taskTHREAD]); |
|
TAILQ_REMOVE(&root->root_thread, TASK_ID(task), task_node); |
|
pthread_mutex_unlock(&root->root_mtx[taskTHREAD]); |
|
task = _sched_unuseTask(task); |
|
} else |
|
TASK_VAL(task) = (u_long) tid; |
|
pthread_attr_destroy(&attr); |
|
} else |
|
task = _sched_unuseTask(task); |
|
|
|
return task; |
|
} |
|
|