--- libaitsched/src/tasks.c 2013/08/22 15:28:04 1.18 +++ libaitsched/src/tasks.c 2013/08/26 14:29:20 1.20.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tasks.c,v 1.18 2013/08/22 15:28:04 misho Exp $ +* $Id: tasks.c,v 1.20.2.1 2013/08/26 14:29:20 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -117,12 +117,6 @@ _sched_threadCleanup(sched_task_t *t) if (TASK_FLAG(t) == PTHREAD_CREATE_JOINABLE) pthread_detach(pthread_self()); - - pthread_mutex_lock(&TASK_ROOT(t)->root_mtx[taskTHREAD]); - TAILQ_REMOVE(&TASK_ROOT(t)->root_thread, t, task_node); - pthread_mutex_unlock(&TASK_ROOT(t)->root_mtx[taskTHREAD]); - - sched_unuseTask(t); } void * _sched_threadWrapper(sched_task_t *t) @@ -140,6 +134,11 @@ _sched_threadWrapper(sched_task_t *t) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); + pthread_mutex_lock(&TASK_ROOT(t)->root_mtx[taskTHREAD]); + TAILQ_REMOVE(&TASK_ROOT(t)->root_thread, t, task_node); + pthread_mutex_unlock(&TASK_ROOT(t)->root_mtx[taskTHREAD]); + sched_unuseTask(t); + /* notify parent, thread is ready for execution */ sem_post(s); pthread_testcancel(); @@ -149,6 +148,37 @@ _sched_threadWrapper(sched_task_t *t) pthread_cleanup_pop(42); TASK_ROOT(t)->root_ret = ret; pthread_exit(ret); +} +#endif + +#if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME) +void * +_sched_rtcWrapper(sched_task_t *t) +{ + sched_task_func_t func; + sched_task_t *task; + sched_root_task_t *r; + + if (!t || !TASK_ROOT(t) || !TASK_DATA(t)) + return NULL; + else { + r = TASK_ROOT(t); + task = (sched_task_t*) TASK_DATA(t); + func = TASK_FUNC(task); + } + +#ifdef HAVE_LIBPTHREAD + pthread_mutex_lock(&r->root_mtx[taskRTC]); +#endif + TAILQ_REMOVE(&r->root_rtc, task, task_node); +#ifdef HAVE_LIBPTHREAD + pthread_mutex_unlock(&r->root_mtx[taskRTC]); +#endif + sched_unuseTask(task); + + timer_delete((timer_t) TASK_DATLEN(t)); + + return func(task); } #endif