|
version 1.10.2.8, 2012/08/02 12:19:29
|
version 1.12.4.1, 2012/08/21 11:07:16
|
|
Line 482 schedAlarm(sched_root_task_t * __restrict root, sched_
|
Line 482 schedAlarm(sched_root_task_t * __restrict root, sched_
|
| return task; |
return task; |
| } |
} |
| |
|
| #ifdef EVFILT_AIO | #ifdef AIO_SUPPORT |
| /* |
/* |
| * schedAIO() - Add AIO task to scheduler queue |
* schedAIO() - Add AIO task to scheduler queue |
| * |
* |
|
Line 647 schedAIOWrite(sched_root_task_t * __restrict root, sch
|
Line 647 schedAIOWrite(sched_root_task_t * __restrict root, sch
|
| |
|
| #ifdef EVFILT_LIO |
#ifdef EVFILT_LIO |
| /* |
/* |
| |
* schedLIO() - Add AIO bulk tasks to scheduler queue |
| |
* |
| |
* @root = root task |
| |
* @func = task execution function |
| |
* @arg = 1st func argument |
| |
* @acbs = AIO cb structure addresses |
| |
* @opt_data = Optional data |
| |
* @opt_dlen = Optional data length |
| |
* return: NULL error or !=NULL new queued task |
| |
*/ |
| |
sched_task_t * |
| |
schedLIO(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, |
| |
struct aiocb ** __restrict acbs, void *opt_data, size_t opt_dlen) |
| |
{ |
| |
sched_task_t *task; |
| |
void *ptr; |
| |
|
| |
if (!root || !func || !acbs || !opt_dlen) |
| |
return NULL; |
| |
|
| |
/* get new task */ |
| |
if (!(task = _sched_useTask(root))) |
| |
return NULL; |
| |
|
| |
task->task_func = func; |
| |
TASK_TYPE(task) = taskLIO; |
| |
TASK_ROOT(task) = root; |
| |
|
| |
TASK_ARG(task) = arg; |
| |
TASK_VAL(task) = (u_long) acbs; |
| |
|
| |
TASK_DATA(task) = opt_data; |
| |
TASK_DATLEN(task) = opt_dlen; |
| |
|
| |
if (root->root_hooks.hook_add.lio) |
| |
ptr = root->root_hooks.hook_add.lio(task, NULL); |
| |
else |
| |
ptr = NULL; |
| |
|
| |
if (!ptr) { |
| |
#ifdef HAVE_LIBPTHREAD |
| |
pthread_mutex_lock(&root->root_mtx[taskLIO]); |
| |
#endif |
| |
TAILQ_INSERT_TAIL(&root->root_lio, TASK_ID(task), task_node); |
| |
#ifdef HAVE_LIBPTHREAD |
| |
pthread_mutex_unlock(&root->root_mtx[taskLIO]); |
| |
#endif |
| |
} else |
| |
task = _sched_unuseTask(task); |
| |
|
| |
return task; |
| |
} |
| |
|
| |
/* |
| * schedLIORead() - Add list of AIO read tasks to scheduler queue |
* schedLIORead() - Add list of AIO read tasks to scheduler queue |
| * |
* |
| * @root = root task |
* @root = root task |
|
Line 691 schedLIORead(sched_root_task_t * __restrict root, sche
|
Line 745 schedLIORead(sched_root_task_t * __restrict root, sche
|
| for (i = 0; i < nbufs; i++) |
for (i = 0; i < nbufs; i++) |
| if (acb[i]) |
if (acb[i]) |
| free(acb[i]); |
free(acb[i]); |
| free(acb); | free(acb); |
| return NULL; |
return NULL; |
| } else |
} else |
| memset(acb[i], 0, sizeof(struct aiocb)); |
memset(acb[i], 0, sizeof(struct aiocb)); |
|
Line 708 schedLIORead(sched_root_task_t * __restrict root, sche
|
Line 762 schedLIORead(sched_root_task_t * __restrict root, sche
|
| |
|
| if (lio_listio(LIO_NOWAIT, acb, nbufs, &sig)) { |
if (lio_listio(LIO_NOWAIT, acb, nbufs, &sig)) { |
| LOGERR; |
LOGERR; |
| |
for (i = 0; i < nbufs; i++) |
| |
if (acb[i]) |
| |
free(acb[i]); |
| |
free(acb); |
| return NULL; |
return NULL; |
| } |
} |
| |
|
| return schedAIO(root, func, arg, (void*) acb, bufs, nbufs); | return schedLIO(root, func, arg, (void*) acb, bufs, nbufs); |
| } |
} |
| |
|
| /* |
/* |
|
Line 759 schedLIOWrite(sched_root_task_t * __restrict root, sch
|
Line 817 schedLIOWrite(sched_root_task_t * __restrict root, sch
|
| for (i = 0; i < nbufs; i++) |
for (i = 0; i < nbufs; i++) |
| if (acb[i]) |
if (acb[i]) |
| free(acb[i]); |
free(acb[i]); |
| free(acb); | free(acb); |
| return NULL; |
return NULL; |
| } else |
} else |
| memset(acb[i], 0, sizeof(struct aiocb)); |
memset(acb[i], 0, sizeof(struct aiocb)); |
|
Line 776 schedLIOWrite(sched_root_task_t * __restrict root, sch
|
Line 834 schedLIOWrite(sched_root_task_t * __restrict root, sch
|
| |
|
| if (lio_listio(LIO_NOWAIT, acb, nbufs, &sig)) { |
if (lio_listio(LIO_NOWAIT, acb, nbufs, &sig)) { |
| LOGERR; |
LOGERR; |
| |
for (i = 0; i < nbufs; i++) |
| |
if (acb[i]) |
| |
free(acb[i]); |
| |
free(acb); |
| return NULL; |
return NULL; |
| } |
} |
| |
|
| return schedAIO(root, func, arg, (void*) acb, bufs, nbufs); | return schedLIO(root, func, arg, (void*) acb, bufs, nbufs); |
| } |
} |
| #endif /* EVFILT_LIO */ |
#endif /* EVFILT_LIO */ |
| #endif /* EVFILT_AIO */ | #endif /* AIO_SUPPORT */ |
| |
|
| /* |
/* |
| * schedTimer() - Add TIMER task to scheduler queue |
* schedTimer() - Add TIMER task to scheduler queue |
|
Line 917 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 942 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 1064 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; |
| |
} |
| |
|