--- libaitsched/src/tasks.c 2013/08/26 08:20:55 1.19 +++ libaitsched/src/tasks.c 2013/08/26 13:26:56 1.19.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: tasks.c,v 1.19 2013/08/26 08:20:55 misho Exp $ +* $Id: tasks.c,v 1.19.2.1 2013/08/26 13:26:56 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -129,17 +129,36 @@ _sched_threadWrapper(sched_task_t *t) { void *ret = NULL; sem_t *s = NULL; + sched_root_task_t *r; if (!t || !TASK_ROOT(t) || !TASK_RET(t)) pthread_exit(ret); - else + else { s = (sem_t*) TASK_RET(t); + r = TASK_ROOT(t); + } pthread_cleanup_push((void (*)(void*)) _sched_threadCleanup, t); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); +#ifdef HAVE_LIBPTHREAD + pthread_mutex_lock(&r->root_mtx[taskTHREAD]); +#endif + TAILQ_REMOVE(&r->root_thread, t, task_node); +#ifdef HAVE_LIBPTHREAD + pthread_mutex_unlock(&r->root_mtx[taskTHREAD]); +#endif + t->task_type = taskUNUSE; +#ifdef HAVE_LIBPTHREAD + pthread_mutex_lock(&r->root_mtx[taskUNUSE]); +#endif + TAILQ_INSERT_TAIL(&r->root_unuse, t, task_node); +#ifdef HAVE_LIBPTHREAD + pthread_mutex_unlock(&r->root_mtx[taskUNUSE]); +#endif + /* notify parent, thread is ready for execution */ sem_post(s); pthread_testcancel(); @@ -159,15 +178,34 @@ _sched_rtcWrapper(sched_task_t *t) void *ret = NULL; 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 + task->task_type = taskUNUSE; +#ifdef HAVE_LIBPTHREAD + pthread_mutex_lock(&r->root_mtx[taskUNUSE]); +#endif + TAILQ_INSERT_TAIL(&r->root_unuse, task, task_node); +#ifdef HAVE_LIBPTHREAD + pthread_mutex_unlock(&r->root_mtx[taskUNUSE]); +#endif + ret = func(task); + timer_delete((timer_t) TASK_DATLEN(t)); return ret; }