--- libaitsched/src/hooks.c 2012/08/21 11:45:35 1.13.2.2 +++ libaitsched/src/hooks.c 2012/08/22 13:37:23 1.14.2.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: hooks.c,v 1.13.2.2 2012/08/21 11:45:35 misho Exp $ +* $Id: hooks.c,v 1.14.2.2 2012/08/22 13:37:23 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -210,7 +210,11 @@ sched_hook_cancel(void *task, void *arg __unused) case taskTHREAD: #ifdef HAVE_LIBPTHREAD pthread_cancel((pthread_t) TASK_VAL(t)); + if (TASK_FLAG(t) == PTHREAD_CREATE_JOINABLE) /* joinable thread */ + schedTask(TASK_ROOT(t), _sched_threadJoin, TASK_ARG(t), + TASK_VAL(t), TASK_DATA(t), TASK_DATLEN(t)); #endif + TASK_UNLOCK(t); default: return NULL; } @@ -218,6 +222,42 @@ sched_hook_cancel(void *task, void *arg __unused) kevent(TASK_ROOT(t)->root_kq, chg, 1, NULL, 0, &timeout); return NULL; } + +#ifdef HAVE_LIBPTHREAD +/* + * sched_hook_thread() - Default THREAD hook + * + * @task = current task + * @arg = pthread attributes + * return: <0 errors and 0 ok + */ +void * +sched_hook_thread(void *task, void *arg) +{ + sched_task_t *t = task; + pthread_t tid; + sigset_t ns, os; + + if (!t || !TASK_ROOT(t)) + return (void*) -1; + + sigfillset(&ns); + pthread_sigmask(SIG_BLOCK, &ns, &os); + if (pthread_create(&tid, (pthread_attr_t*) arg, + (void *(*)(void*)) TASK_FUNC(t), t)) { + LOGERR; + pthread_sigmask(SIG_SETMASK, &os, NULL); + return (void*) -1; + } + pthread_sigmask(SIG_SETMASK, &os, NULL); + + if (!TASK_ISLOCKED(t)) + TASK_LOCK(t); + + TASK_VAL(t) = (u_long) tid; + return NULL; +} +#endif /* * sched_hook_read() - Default READ hook