X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=sched.c;h=66a17418027a5e9fa2d92bee412cf682561115b9;hp=7b5ca63d29dc78aeda551bd11fb63819dce7bbad;hb=4867d9a4948aadde4dd59436e1c5fb0fc141ba89;hpb=7544e25415144894b58e48ab17de21a693ea00c7 diff --git a/sched.c b/sched.c index 7b5ca63d..66a17418 100644 --- a/sched.c +++ b/sched.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "para.h" #include "ipc.h" @@ -46,14 +47,25 @@ static void unregister_task(struct task *t) list_del(&t->post_select_node); } +static inline bool timeout_is_zero(struct sched *s) +{ + struct timeval *tv = &s->select_timeout; + return tv->tv_sec == 0 && tv->tv_usec == 0; +} + static void sched_preselect(struct sched *s) { struct task *t, *tmp; list_for_each_entry_safe(t, tmp, &pre_select_list, pre_select_node) { - if (t->pre_select) - t->pre_select(s, t); - if (t->error < 0) + if (t->error < 0) { unregister_task(t); + continue; + } + if (!t->pre_select) + continue; + t->pre_select(s, t); + if (timeout_is_zero(s)) + break; } } @@ -131,21 +143,26 @@ again: sched_preselect(s); if (list_empty(&pre_select_list) && list_empty(&post_select_list)) return 0; - ret = s->select_function(s->max_fileno + 1, &s->rfds, &s->wfds, - &s->select_timeout); - if (ret < 0) - return ret; - if (ret == 0) { - /* - * APUE: Be careful not to check the descriptor sets on return - * unless the return value is greater than zero. The return - * state of the descriptor sets is implementation dependent if - * either a signal is caught or the timer expires. - */ + if (!timeout_is_zero(s)) { + ret = s->select_function(s->max_fileno + 1, &s->rfds, &s->wfds, + &s->select_timeout); + if (ret < 0) + return ret; + if (ret == 0) { + /* + * APUE: Be careful not to check the descriptor sets on return + * unless the return value is greater than zero. The return + * state of the descriptor sets is implementation dependent if + * either a signal is caught or the timer expires. + */ + FD_ZERO(&s->rfds); + FD_ZERO(&s->wfds); + } + gettimeofday(now, NULL); + } else { FD_ZERO(&s->rfds); FD_ZERO(&s->wfds); } - gettimeofday(now, NULL); sched_post_select(s); if (list_empty(&pre_select_list) && list_empty(&post_select_list)) return 0; @@ -297,17 +314,19 @@ void sched_request_timeout_ms(long unsigned ms, struct sched *s) * \param barrier Absolute time before select() should return. * \param s Pointer to the scheduler struct. * - * If \a barrier is in the past, this function does nothing. + * \return If \a barrier is in the past, this function does nothing and returns + * zero. Otherwise it returns one. * * \sa sched_request_barrier_or_min_delay(). */ -void sched_request_barrier(struct timeval *barrier, struct sched *s) +int sched_request_barrier(struct timeval *barrier, struct sched *s) { struct timeval diff; if (tv_diff(now, barrier, &diff) > 0) - return; + return 0; sched_request_timeout(&diff, s); + return 1; } /** @@ -316,15 +335,19 @@ void sched_request_barrier(struct timeval *barrier, struct sched *s) * \param barrier Absolute time before select() should return. * \param s Pointer to the scheduler struct. * - * If \a barrier is in the past, this function requests a minimal timeout. + * \return If \a barrier is in the past, this function requests a minimal + * timeout and returns zero. Otherwise it returns one. * * \sa sched_min_delay(), sched_request_barrier(). */ -void sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s) +int sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s) { struct timeval diff; - if (tv_diff(now, barrier, &diff) > 0) - return sched_min_delay(s); + if (tv_diff(now, barrier, &diff) > 0) { + sched_min_delay(s); + return 0; + } sched_request_timeout(&diff, s); + return 1; }