--- libaitsched/src/hooks.c 2014/01/27 16:52:56 1.24.4.1 +++ libaitsched/src/hooks.c 2014/01/27 17:08:02 1.24.4.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: hooks.c,v 1.24.4.1 2014/01/27 16:52:56 misho Exp $ +* $Id: hooks.c,v 1.24.4.2 2014/01/27 17:08:02 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -618,12 +618,12 @@ sched_hook_fetch(void *root, void *arg __unused) { sched_root_task_t *r = root; sched_task_t *task, *tmp; - struct timespec now; + struct timespec now, m, mtmp; #ifndef KQ_DISABLE struct kevent evt[1], res[KQ_EVENTS]; struct timespec *timeout, m, mtmp; #else - struct timeval *timeout, m, mtmp, now2; + struct timeval *timeout, tv; #endif register int i, flg; int en; @@ -683,7 +683,6 @@ sched_hook_fetch(void *root, void *arg __unused) #ifdef TIMER_WITHOUT_SORT clock_gettime(CLOCK_MONOTONIC, &now); -#ifndef KQ_DISABLE sched_timespecclear(&r->root_wait); TAILQ_FOREACH(task, &r->root_timer, task_node) { if (!sched_timespecisset(&r->root_wait)) @@ -691,80 +690,48 @@ sched_hook_fetch(void *root, void *arg __unused) else if (sched_timespeccmp(&TASK_TS(task), &r->root_wait, -) < 0) r->root_wait = TASK_TS(task); } -#else - sched_timevalclear(&r->root_wait); - TAILQ_FOREACH(task, &r->root_timer, task_node) { - if (!sched_timevalisset(&r->root_wait)) - TASK_TS2TV(task, &r->root_wait); - else { - TASK_TS2TV(task, &m); - if (sched_timevalcmp(&m, &r->root_wait, -) < 0) - TASK_TS2TV(task, &r->root_wait); - } - } -#endif /* KQ_DISABLE */ if (TAILQ_FIRST(&r->root_timer)) { m = r->root_wait; -#ifndef KQ_DISABLE sched_timespecsub(&m, &now, &mtmp); -#else - sched_timespec2val(&now, &now2); - sched_timevalsub(&m, &now2, &mtmp); -#endif /* KQ_DISABLE */ r->root_wait = mtmp; } else { /* set wait INFTIM */ -#ifndef KQ_DISABLE sched_timespecinf(&r->root_wait); -#else - sched_timevalinf(&r->root_wait); -#endif /* KQ_DISABLE */ } #else /* ! TIMER_WITHOUT_SORT */ if (!TAILQ_FIRST(&r->root_task) && (task = TAILQ_FIRST(&r->root_timer))) { clock_gettime(CLOCK_MONOTONIC, &now); -#ifndef KQ_DISABLE m = TASK_TS(task); sched_timespecsub(&m, &now, &mtmp); -#else - TASK_TS2TV(task, &m); - sched_timespec2val(&now, &now2); - sched_timevalsub(&m, &now2, &mtmp); -#endif /* KQ_DISABLE */ r->root_wait = mtmp; } else { /* set wait INFTIM */ -#ifndef KQ_DISABLE sched_timespecinf(&r->root_wait); -#else - sched_timevalinf(&r->root_wait); -#endif /* KQ_DISABLE */ } #endif /* TIMER_WITHOUT_SORT */ /* if present member of task, set NOWAIT */ if (TAILQ_FIRST(&r->root_task)) -#ifndef KQ_DISABLE sched_timespecclear(&r->root_wait); -#else - sched_timevalclear(&r->root_wait); -#endif /* KQ_DISABLE */ + if (r->root_wait.tv_sec != -1 && r->root_wait.tv_nsec != -1) { #ifndef KQ_DISABLE - if (r->root_wait.tv_sec != -1 && r->root_wait.tv_nsec != -1) -#else - if (r->root_wait.tv_sec != -1 && r->root_wait.tv_usec != -1) -#endif /* KQ_DISABLE */ timeout = &r->root_wait; -#ifndef KQ_DISABLE - else if (sched_timespecisinf(&r->root_poll)) #else - else if (sched_timevalisinf(&r->root_poll)) + sched_timespec2val(&r->root_wait, &tv); + timeout = &tv; #endif /* KQ_DISABLE */ + } else if (sched_timespecisinf(&r->root_poll)) timeout = NULL; - else + else { +#ifndef KQ_DISABLE timeout = &r->root_poll; +#else + sched_timespec2val(&r->root_poll, &tv); + timeout = &tv; +#endif /* KQ_DISABLE */ + } #ifndef KQ_DISABLE if ((en = kevent(r->root_kq, NULL, 0, res, KQ_EVENTS, timeout)) == -1) {