X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=sched.c;h=4ca040f44f337a126ab24b4ec36fb297fa273687;hb=bb899fb1a0c279a2890ff30d11bf7aec50fb92ed;hp=aac8efed1bcf8d897e6aef4d07973f2babc8d4f4;hpb=a79e210f33334b273d11c92a430dd477284ee95a;p=paraslash.git diff --git a/sched.c b/sched.c index aac8efed..4ca040f4 100644 --- a/sched.c +++ b/sched.c @@ -137,12 +137,12 @@ int schedule(struct sched *s) again: FD_ZERO(&s->rfds); FD_ZERO(&s->wfds); - s->select_timeout = s->default_timeout; + s->timeout = s->default_timeout; s->max_fileno = -1; clock_get_realtime(&now_struct); sched_preselect(s); ret = s->select_function(s->max_fileno + 1, &s->rfds, &s->wfds, - &s->select_timeout); + s->timeout); if (ret < 0) return ret; if (ret == 0) { @@ -370,7 +370,7 @@ void task_notify_all(struct sched *s, int err) */ void sched_min_delay(struct sched *s) { - s->select_timeout.tv_sec = s->select_timeout.tv_usec = 0; + s->timeout = 0; } /** @@ -387,8 +387,9 @@ void sched_min_delay(struct sched *s) */ void sched_request_timeout(struct timeval *to, struct sched *s) { - if (tv_diff(&s->select_timeout, to, NULL) > 0) - s->select_timeout = *to; + long unsigned ms = tv2ms(to); + if (s->timeout > ms) + s->timeout = ms; } /** @@ -450,3 +451,45 @@ int sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s) sched_request_timeout(&diff, s); return 1; } + +static void sched_fd_set(int fd, fd_set *fds, int *max_fileno) +{ + assert(fd >= 0 && fd < FD_SETSIZE); +#if 0 + { + int flags = fcntl(fd, F_GETFL); + if (!(flags & O_NONBLOCK)) { + PARA_EMERG_LOG("fd %d is a blocking file descriptor\n", fd); + exit(EXIT_FAILURE); + } + } +#endif + FD_SET(fd, fds); + *max_fileno = PARA_MAX(*max_fileno, fd); +} + +/** + * Instruct the scheduler to monitor an fd for readiness for reading. + * + * \param fd The file descriptor. + * \param s The scheduler. + * + * \sa \ref sched_monitor_writefd(). + */ +void sched_monitor_readfd(int fd, struct sched *s) +{ + sched_fd_set(fd, &s->rfds, &s->max_fileno); +} + +/** + * Instruct the scheduler to monitor an fd for readiness for writing. + * + * \param fd The file descriptor. + * \param s The scheduler. + * + * \sa \ref sched_monitor_readfd(). + */ +void sched_monitor_writefd(int fd, struct sched *s) +{ + sched_fd_set(fd, &s->wfds, &s->max_fileno); +}