--- libaitsched/src/hooks.c 2014/04/27 16:20:37 1.27 +++ libaitsched/src/hooks.c 2014/05/21 22:09:01 1.27.2.3 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: hooks.c,v 1.27 2014/04/27 16:20:37 misho Exp $ +* $Id: hooks.c,v 1.27.2.3 2014/05/21 22:09:01 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -62,7 +62,7 @@ sched_hook_init(void *root, void *arg __unused) if (!r) return (void*) -1; -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE r->root_kq = kqueue(); if (r->root_kq == -1) { LOGERR; @@ -92,7 +92,7 @@ sched_hook_fini(void *root, void *arg __unused) if (!r) return (void*) -1; -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE if (r->root_kq > 2) { close(r->root_kq); r->root_kq = 0; @@ -117,7 +117,7 @@ void * sched_hook_cancel(void *task, void *arg __unused) { sched_task_t *t = task; -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE struct kevent chg[1]; struct timespec timeout = { 0, 0 }; #else @@ -134,13 +134,13 @@ sched_hook_cancel(void *task, void *arg __unused) if (!t || !TASK_ROOT(t)) return (void*) -1; -#ifdef KQ_DISABLE +#if SUP_ENABLE != KQ_ENABLE r = TASK_ROOT(t); #endif switch (TASK_TYPE(t)) { case taskREAD: -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE #ifdef __NetBSD__ EV_SET(&chg[0], TASK_FD(t), EVFILT_READ, EV_DELETE, 0, 0, (intptr_t) TASK_FD(t)); #else @@ -158,7 +158,7 @@ sched_hook_cancel(void *task, void *arg __unused) #endif break; case taskWRITE: -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE #ifdef __NetBSD__ EV_SET(&chg[0], TASK_FD(t), EVFILT_WRITE, EV_DELETE, 0, 0, (intptr_t) TASK_FD(t)); #else @@ -176,7 +176,7 @@ sched_hook_cancel(void *task, void *arg __unused) #endif break; case taskALARM: -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE #ifdef __NetBSD__ EV_SET(&chg[0], (uintptr_t) TASK_DATA(t), EVFILT_TIMER, EV_DELETE, 0, 0, (intptr_t) TASK_DATA(t)); @@ -187,7 +187,7 @@ sched_hook_cancel(void *task, void *arg __unused) #endif break; case taskNODE: -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE #ifdef __NetBSD__ EV_SET(&chg[0], TASK_FD(t), EVFILT_VNODE, EV_DELETE, 0, 0, (intptr_t) TASK_FD(t)); #else @@ -196,7 +196,7 @@ sched_hook_cancel(void *task, void *arg __unused) #endif break; case taskPROC: -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE #ifdef __NetBSD__ EV_SET(&chg[0], TASK_VAL(t), EVFILT_PROC, EV_DELETE, 0, 0, (intptr_t) TASK_VAL(t)); #else @@ -205,7 +205,7 @@ sched_hook_cancel(void *task, void *arg __unused) #endif break; case taskSIGNAL: -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE #ifdef __NetBSD__ EV_SET(&chg[0], TASK_VAL(t), EVFILT_SIGNAL, EV_DELETE, 0, 0, (intptr_t) TASK_VAL(t)); #else @@ -217,7 +217,7 @@ sched_hook_cancel(void *task, void *arg __unused) break; #ifdef AIO_SUPPORT case taskAIO: -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE #ifdef __NetBSD__ EV_SET(&chg[0], TASK_VAL(t), EVFILT_AIO, EV_DELETE, 0, 0, (intptr_t) TASK_VAL(t)); #else @@ -234,7 +234,7 @@ sched_hook_cancel(void *task, void *arg __unused) break; #ifdef EVFILT_LIO case taskLIO: -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE #ifdef __NetBSD__ EV_SET(&chg[0], TASK_VAL(t), EVFILT_LIO, EV_DELETE, 0, 0, (intptr_t) TASK_VAL(t)); #else @@ -256,7 +256,7 @@ sched_hook_cancel(void *task, void *arg __unused) #endif /* AIO_SUPPORT */ #ifdef EVFILT_USER case taskUSER: -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE #ifdef __NetBSD__ EV_SET(&chg[0], TASK_VAL(t), EVFILT_USER, EV_DELETE, 0, 0, (intptr_t) TASK_VAL(t)); #else @@ -267,7 +267,8 @@ sched_hook_cancel(void *task, void *arg __unused) #endif /* EVFILT_USER */ case taskTHREAD: #ifdef HAVE_LIBPTHREAD - pthread_cancel((pthread_t) TASK_VAL(t)); + if (TASK_VAL(t)) + pthread_cancel((pthread_t) TASK_VAL(t)); #endif return NULL; #if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME) && defined(HAVE_TIMER_DELETE) @@ -280,7 +281,7 @@ sched_hook_cancel(void *task, void *arg __unused) return NULL; } -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE kevent(TASK_ROOT(t)->root_kq, chg, 1, NULL, 0, &timeout); #endif return NULL; @@ -333,7 +334,7 @@ void * sched_hook_read(void *task, void *arg __unused) { sched_task_t *t = task; -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE struct kevent chg[1]; struct timespec timeout = { 0, 0 }; #else @@ -342,11 +343,11 @@ sched_hook_read(void *task, void *arg __unused) if (!t || !TASK_ROOT(t)) return (void*) -1; -#ifdef KQ_DISABLE +#if SUP_ENABLE != KQ_ENABLE r = TASK_ROOT(t); #endif -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE #ifdef __NetBSD__ EV_SET(&chg[0], TASK_FD(t), EVFILT_READ, EV_ADD | EV_CLEAR, 0, 0, (intptr_t) TASK_FD(t)); #else @@ -379,7 +380,7 @@ void * sched_hook_write(void *task, void *arg __unused) { sched_task_t *t = task; -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE struct kevent chg[1]; struct timespec timeout = { 0, 0 }; #else @@ -388,11 +389,11 @@ sched_hook_write(void *task, void *arg __unused) if (!t || !TASK_ROOT(t)) return (void*) -1; -#ifdef KQ_DISABLE +#if SUP_ENABLE != KQ_ENABLE r = TASK_ROOT(t); #endif -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE #ifdef __NetBSD__ EV_SET(&chg[0], TASK_FD(t), EVFILT_WRITE, EV_ADD | EV_CLEAR, 0, 0, (intptr_t) TASK_FD(t)); #else @@ -424,7 +425,7 @@ sched_hook_write(void *task, void *arg __unused) void * sched_hook_alarm(void *task, void *arg __unused) { -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE sched_task_t *t = task; struct kevent chg[1]; struct timespec timeout = { 0, 0 }; @@ -463,7 +464,7 @@ sched_hook_alarm(void *task, void *arg __unused) void * sched_hook_node(void *task, void *arg __unused) { -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE sched_task_t *t = task; struct kevent chg[1]; struct timespec timeout = { 0, 0 }; @@ -502,7 +503,7 @@ sched_hook_node(void *task, void *arg __unused) void * sched_hook_proc(void *task, void *arg __unused) { -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE sched_task_t *t = task; struct kevent chg[1]; struct timespec timeout = { 0, 0 }; @@ -539,7 +540,7 @@ sched_hook_proc(void *task, void *arg __unused) void * sched_hook_signal(void *task, void *arg __unused) { -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE sched_task_t *t = task; struct kevent chg[1]; struct timespec timeout = { 0, 0 }; @@ -595,7 +596,7 @@ sched_hook_signal(void *task, void *arg __unused) void * sched_hook_user(void *task, void *arg __unused) { -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE sched_task_t *t = task; struct kevent chg[1]; struct timespec timeout = { 0, 0 }; @@ -636,7 +637,7 @@ sched_hook_fetch(void *root, void *arg __unused) sched_root_task_t *r = root; sched_task_t *task, *tmp; struct timespec now, m, mtmp; -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE struct kevent evt[1], res[KQ_EVENTS]; struct timespec *timeout; #else @@ -734,30 +735,30 @@ sched_hook_fetch(void *root, void *arg __unused) sched_timespecclear(&r->root_wait); if (r->root_wait.tv_sec != -1 && r->root_wait.tv_nsec != -1) { -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE timeout = &r->root_wait; #else sched_timespec2val(&r->root_wait, &tv); timeout = &tv; -#endif /* KQ_DISABLE */ +#endif /* KQ_SUPPORT */ } else if (sched_timespecisinf(&r->root_poll)) timeout = NULL; else { -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE timeout = &r->root_poll; #else sched_timespec2val(&r->root_poll, &tv); timeout = &tv; -#endif /* KQ_DISABLE */ +#endif /* KQ_SUPPORT */ } -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE if ((en = kevent(r->root_kq, NULL, 0, res, KQ_EVENTS, timeout)) == -1) { #else rfd = xfd = r->root_fds[0]; wfd = r->root_fds[1]; if ((en = select(r->root_kq, &rfd, &wfd, &xfd, timeout)) == -1) { -#endif /* KQ_DISABLE */ +#endif /* KQ_SUPPORT */ if (r->root_hooks.hook_exec.exception) { if (r->root_hooks.hook_exec.exception(r, NULL)) return NULL; @@ -769,7 +770,7 @@ sched_hook_fetch(void *root, void *arg __unused) /* kevent dispatcher */ now.tv_sec = now.tv_nsec = 0; /* Go and catch the cat into pipes ... */ -#ifndef KQ_DISABLE +#if SUP_ENABLE == KQ_ENABLE for (i = 0; i < en; i++) { memcpy(evt, &res[i], sizeof evt); evt->flags = EV_DELETE; @@ -1257,7 +1258,7 @@ sched_hook_fetch(void *root, void *arg __unused) break; if (i > 2) r->root_kq = i + 1; -#endif /* KQ_DISABLE */ +#endif /* KQ_SUPPORT */ skip_event: /* timer update & put in ready queue */