--- libaitsched/src/hooks.c 2012/08/08 23:04:41 1.13 +++ libaitsched/src/hooks.c 2013/05/30 09:13:52 1.17 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: hooks.c,v 1.13 2012/08/08 23:04:41 misho Exp $ +* $Id: hooks.c,v 1.17 2013/05/30 09:13:52 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 +Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -110,8 +110,8 @@ sched_hook_cancel(void *task, void *arg __unused) #ifdef AIO_SUPPORT struct aiocb *acb; #ifdef EVFILT_LIO + register int i = 0; struct aiocb **acbs; - register int i; #endif /* EVFILT_LIO */ #endif /* AIO_SUPPORT */ @@ -207,6 +207,10 @@ sched_hook_cancel(void *task, void *arg __unused) #endif break; #endif + case taskTHREAD: +#ifdef HAVE_LIBPTHREAD + pthread_cancel((pthread_t) TASK_VAL(t)); +#endif default: return NULL; } @@ -215,7 +219,43 @@ sched_hook_cancel(void *task, void *arg __unused) 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 s, o; + + if (!t || !TASK_ROOT(t)) + return (void*) -1; + + sigfillset(&s); + pthread_sigmask(SIG_BLOCK, &s, &o); + if ((errno = pthread_create(&tid, (pthread_attr_t*) arg, + (void *(*)(void*)) _sched_threadWrapper, t))) { + LOGERR; + pthread_sigmask(SIG_SETMASK, &o, NULL); + return (void*) -1; + } else + TASK_VAL(t) = (u_long) tid; + + if (!TASK_ISLOCKED(t)) + TASK_LOCK(t); + + pthread_sigmask(SIG_SETMASK, &o, NULL); + return NULL; +} +#endif + +/* * sched_hook_read() - Default READ hook * * @task = current task @@ -592,8 +632,11 @@ sched_hook_fetch(void *root, void *arg __unused) TAILQ_FOREACH_SAFE(task, &r->root_read, task_node, tmp) { if (TASK_FD(task) != ((intptr_t) res[i].udata)) continue; - else + else { flg++; + TASK_RET(task) = res[i].data; + TASK_FLAG(task) = res[i].fflags; + } /* remove read handle */ #ifdef HAVE_LIBPTHREAD pthread_mutex_lock(&r->root_mtx[taskREAD]); @@ -642,8 +685,11 @@ sched_hook_fetch(void *root, void *arg __unused) TAILQ_FOREACH_SAFE(task, &r->root_write, task_node, tmp) { if (TASK_FD(task) != ((intptr_t) res[i].udata)) continue; - else + else { flg++; + TASK_RET(task) = res[i].data; + TASK_FLAG(task) = res[i].fflags; + } /* remove write handle */ #ifdef HAVE_LIBPTHREAD pthread_mutex_lock(&r->root_mtx[taskWRITE]); @@ -692,8 +738,11 @@ sched_hook_fetch(void *root, void *arg __unused) TAILQ_FOREACH_SAFE(task, &r->root_alarm, task_node, tmp) { if ((uintptr_t) TASK_DATA(task) != ((uintptr_t) res[i].udata)) continue; - else + else { flg++; + TASK_RET(task) = res[i].data; + TASK_FLAG(task) = res[i].fflags; + } /* remove alarm handle */ #ifdef HAVE_LIBPTHREAD pthread_mutex_lock(&r->root_mtx[taskALARM]); @@ -722,8 +771,8 @@ sched_hook_fetch(void *root, void *arg __unused) continue; else { flg++; - TASK_DATA(task) = (void*) (uintptr_t) res[i].data; - TASK_DATLEN(task) = res[i].fflags; + TASK_RET(task) = res[i].data; + TASK_FLAG(task) = res[i].fflags; } /* remove node handle */ #ifdef HAVE_LIBPTHREAD @@ -753,8 +802,8 @@ sched_hook_fetch(void *root, void *arg __unused) continue; else { flg++; - TASK_DATA(task) = (void*) (uintptr_t) res[i].data; - TASK_DATLEN(task) = res[i].fflags; + TASK_RET(task) = res[i].data; + TASK_FLAG(task) = res[i].fflags; } /* remove proc handle */ #ifdef HAVE_LIBPTHREAD @@ -782,8 +831,11 @@ sched_hook_fetch(void *root, void *arg __unused) TAILQ_FOREACH_SAFE(task, &r->root_signal, task_node, tmp) { if (TASK_VAL(task) != ((uintptr_t) res[i].udata)) continue; - else + else { flg++; + TASK_RET(task) = res[i].data; + TASK_FLAG(task) = res[i].fflags; + } /* remove signal handle */ #ifdef HAVE_LIBPTHREAD pthread_mutex_lock(&r->root_mtx[taskSIGNAL]); @@ -812,8 +864,11 @@ sched_hook_fetch(void *root, void *arg __unused) acb = (struct aiocb*) TASK_VAL(task); if (acb != ((struct aiocb*) res[i].udata)) continue; - else + else { flg++; + TASK_RET(task) = res[i].data; + TASK_FLAG(task) = res[i].fflags; + } /* remove user handle */ #ifdef HAVE_LIBPTHREAD pthread_mutex_lock(&r->root_mtx[taskAIO]); @@ -851,8 +906,11 @@ sched_hook_fetch(void *root, void *arg __unused) acbs = (struct aiocb**) TASK_VAL(task); if (acbs != ((struct aiocb**) res[i].udata)) continue; - else + else { flg++; + TASK_RET(task) = res[i].data; + TASK_FLAG(task) = res[i].fflags; + } /* remove user handle */ #ifdef HAVE_LIBPTHREAD pthread_mutex_lock(&r->root_mtx[taskLIO]); @@ -900,8 +958,8 @@ sched_hook_fetch(void *root, void *arg __unused) continue; else { flg++; - TASK_DATA(task) = (void*) res[i].data; - TASK_DATLEN(task) = res[i].fflags; + TASK_RET(task) = res[i].data; + TASK_FLAG(task) = res[i].fflags; } /* remove user handle */ #ifdef HAVE_LIBPTHREAD