--- libaitsched/src/hooks.c 2012/05/03 15:05:09 1.5.2.2 +++ libaitsched/src/hooks.c 2012/05/14 12:09:13 1.6 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: hooks.c,v 1.5.2.2 2012/05/03 15:05:09 misho Exp $ +* $Id: hooks.c,v 1.6 2012/05/14 12:09:13 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -212,7 +212,7 @@ void * sched_hook_fetch(void *root, void *arg __unused) { sched_root_task_t *r = root; - sched_task_t *task; + sched_task_t *task, *tmp; struct timespec now, m, mtmp; struct timespec *timeout; struct kevent evt[1], res[KQ_EVENTS]; @@ -223,7 +223,6 @@ sched_hook_fetch(void *root, void *arg __unused) return NULL; /* get new task by queue priority */ -retry: while ((task = TAILQ_FIRST(&r->root_event))) { #ifdef HAVE_LIBPTHREAD pthread_mutex_lock(&r->root_mtx[taskEVENT]); @@ -306,15 +305,9 @@ retry: if (r->root_hooks.hook_exec.exception) { if (r->root_hooks.hook_exec.exception(r, NULL)) return NULL; - } else + } else if (errno != EINTR) LOGERR; -#ifdef NDEBUG - /* kevent no exit by error, if non-debug version */ - goto retry; -#else - /* diagnostic exit from scheduler if kevent error occur */ return NULL; -#endif } now.tv_sec = now.tv_nsec = 0; @@ -325,7 +318,7 @@ retry: /* Put read/write task to ready queue */ switch (res[i].filter) { case EVFILT_READ: - TAILQ_FOREACH(task, &r->root_read, task_node) { + TAILQ_FOREACH_SAFE(task, &r->root_read, task_node, tmp) { if (TASK_FD(task) != ((intptr_t) res[i].udata)) continue; /* remove read handle */ @@ -370,7 +363,7 @@ retry: } break; case EVFILT_WRITE: - TAILQ_FOREACH(task, &r->root_write, task_node) { + TAILQ_FOREACH_SAFE(task, &r->root_write, task_node, tmp) { if (TASK_FD(task) != ((intptr_t) res[i].udata)) continue; /* remove write handle */ @@ -427,7 +420,7 @@ retry: /* timer update & put in ready queue */ clock_gettime(CLOCK_MONOTONIC, &now); - TAILQ_FOREACH(task, &r->root_timer, task_node) + TAILQ_FOREACH_SAFE(task, &r->root_timer, task_node, tmp) if (sched_timespeccmp(&now, &TASK_TS(task), -) >= 0) { #ifdef HAVE_LIBPTHREAD pthread_mutex_lock(&r->root_mtx[taskTIMER]);