--- libaitsched/src/hooks.c 2014/05/21 22:22:57 1.27.2.4 +++ libaitsched/src/hooks.c 2014/05/21 23:05:43 1.27.2.5 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: hooks.c,v 1.27.2.4 2014/05/21 22:22:57 misho Exp $ +* $Id: hooks.c,v 1.27.2.5 2014/05/21 23:05:43 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -128,7 +128,7 @@ sched_hook_cancel(void *task, void *arg __unused) struct timespec timeout = { 0, 0 }; #else sched_root_task_t *r = NULL; - register int i; + register int i = -1; #endif #ifdef AIO_SUPPORT struct aiocb *acb; @@ -152,6 +152,8 @@ sched_hook_cancel(void *task, void *arg __unused) #else EV_SET(&chg[0], TASK_FD(t), EVFILT_READ, EV_DELETE, 0, 0, (void*) TASK_FD(t)); #endif +#elif SUP_ENABLE == EP_SUPPORT + i = TASK_FD(t); #else FD_CLR(TASK_FD(t), &r->root_fds[0]); @@ -170,6 +172,8 @@ sched_hook_cancel(void *task, void *arg __unused) #else EV_SET(&chg[0], TASK_FD(t), EVFILT_WRITE, EV_DELETE, 0, 0, (void*) TASK_FD(t)); #endif +#elif SUP_ENABLE == EP_SUPPORT + i = TASK_FD(t); #else FD_CLR(TASK_FD(t), &r->root_fds[1]); @@ -289,6 +293,9 @@ sched_hook_cancel(void *task, void *arg __unused) #if SUP_ENABLE == KQ_SUPPORT kevent(TASK_ROOT(t)->root_kq, chg, 1, NULL, 0, &timeout); +#elif SUP_ENABLE == EP_SUPPORT + if (i != -1) + epoll_ctl(TASK_ROOT(t)->root_kq, EPOLL_CTL_DEL, i, NULL); #endif return NULL; } @@ -343,15 +350,14 @@ sched_hook_read(void *task, void *arg __unused) #if SUP_ENABLE == KQ_SUPPORT struct kevent chg[1]; struct timespec timeout = { 0, 0 }; +#elif SUP_ENABLE == EP_SUPPORT + struct epoll_event ee = { .events = EPOLLIN | EPOLLPRI | EPOLLRDHUP, .data.fd = 0 }; #else sched_root_task_t *r = NULL; #endif if (!t || !TASK_ROOT(t)) return (void*) -1; -#if SUP_ENABLE != KQ_SUPPORT - r = TASK_ROOT(t); -#endif #if SUP_ENABLE == KQ_SUPPORT #ifdef __NetBSD__ @@ -366,7 +372,17 @@ sched_hook_read(void *task, void *arg __unused) LOGERR; return (void*) -1; } +#elif SUP_ENABLE == EP_SUPPORT + ee.data.fd = TASK_FD(t); + if (epoll_ctl(TASK_ROOT(t)->root_kq, EPOLL_CTL_ADD, TASK_FD(t), &ee) == -1) { + if (TASK_ROOT(t)->root_hooks.hook_exec.exception) + TASK_ROOT(t)->root_hooks.hook_exec.exception(TASK_ROOT(t), NULL); + else + LOGERR; + return (void*) -1; + } #else + r = TASK_ROOT(t); FD_SET(TASK_FD(t), &r->root_fds[0]); if (TASK_FD(t) >= r->root_kq) r->root_kq = TASK_FD(t) + 1; @@ -389,15 +405,14 @@ sched_hook_write(void *task, void *arg __unused) #if SUP_ENABLE == KQ_SUPPORT struct kevent chg[1]; struct timespec timeout = { 0, 0 }; +#elif SUP_ENABLE == EP_SUPPORT + struct epoll_event ee = { .events = EPOLLOUT, .data.fd = 0 }; #else sched_root_task_t *r = NULL; #endif if (!t || !TASK_ROOT(t)) return (void*) -1; -#if SUP_ENABLE != KQ_SUPPORT - r = TASK_ROOT(t); -#endif #if SUP_ENABLE == KQ_SUPPORT #ifdef __NetBSD__ @@ -412,7 +427,17 @@ sched_hook_write(void *task, void *arg __unused) LOGERR; return (void*) -1; } +#elif SUP_ENABLE == EP_SUPPORT + ee.data.fd = TASK_FD(t); + if (epoll_ctl(TASK_ROOT(t)->root_kq, EPOLL_CTL_ADD, TASK_FD(t), &ee) == -1) { + if (TASK_ROOT(t)->root_hooks.hook_exec.exception) + TASK_ROOT(t)->root_hooks.hook_exec.exception(TASK_ROOT(t), NULL); + else + LOGERR; + return (void*) -1; + } #else + r = TASK_ROOT(t); FD_SET(TASK_FD(t), &r->root_fds[1]); if (TASK_FD(t) >= r->root_kq) r->root_kq = TASK_FD(t) + 1; @@ -646,6 +671,9 @@ sched_hook_fetch(void *root, void *arg __unused) #if SUP_ENABLE == KQ_SUPPORT struct kevent evt[1], res[KQ_EVENTS]; struct timespec *timeout; +#elif SUP_ENABLE == EP_SUPPORT + struct epoll_event res[KQ_EVENTS]; + u_long timeout = 0; #else struct timeval *timeout, tv; fd_set rfd, wfd, xfd; @@ -743,15 +771,23 @@ sched_hook_fetch(void *root, void *arg __unused) if (r->root_wait.tv_sec != -1 && r->root_wait.tv_nsec != -1) { #if SUP_ENABLE == KQ_SUPPORT timeout = &r->root_wait; +#elif SUP_ENABLE == EP_SUPPORT + timeout = r->root_wait.tv_sec * 1000 + r->root_wait.tv_nsec / 1000000; #else sched_timespec2val(&r->root_wait, &tv); timeout = &tv; #endif /* KQ_SUPPORT */ } else if (sched_timespecisinf(&r->root_poll)) +#if SUP_ENABLE == EP_SUPPORT + timeout = -1; +#else timeout = NULL; +#endif else { #if SUP_ENABLE == KQ_SUPPORT timeout = &r->root_poll; +#elif SUP_ENABLE == EP_SUPPORT + timeout = r->root_poll.tv_sec * 1000 + r->root_poll.tv_nsec / 1000000; #else sched_timespec2val(&r->root_poll, &tv); timeout = &tv; @@ -760,6 +796,8 @@ sched_hook_fetch(void *root, void *arg __unused) #if SUP_ENABLE == KQ_SUPPORT if ((en = kevent(r->root_kq, NULL, 0, res, KQ_EVENTS, timeout)) == -1) { +#elif SUP_ENABLE == EP_SUPPORT + if ((en = epoll_wait(r->root_kq, res, KQ_EVENTS, timeout)) == -1) { #else rfd = xfd = r->root_fds[0]; wfd = r->root_fds[1];