/* Either timeout == NULL, meaning wait indefinitely, or timeout !=
NULL, in which case ms_end holds the end time. */
+
while (1) {
- if (timeout) {
- VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */,
- VG_USERREQ__READ_MILLISECOND_TIMER,
- 0, 0, 0, 0);
- my_assert(ms_now != 0xFFFFFFFF);
- if (ms_now >= ms_end) {
- /* timeout; nothing interesting happened. */
- if (rfds) FD_ZERO(rfds);
- if (wfds) FD_ZERO(wfds);
- if (xfds) FD_ZERO(xfds);
- return 0;
- }
- }
+
+ /* First, do a return-immediately select(). */
/* These could be trashed each time round the loop, so restore
them each time. */
if (xfds) *xfds = xfds_copy;
return res;
}
+
+ /* Nothing interesting happened, so we go to sleep for a
+ while. */
+
/* fprintf(stderr, "MY_SELECT: nanosleep\n"); */
/* nanosleep and go round again */
nanosleep_interval.tv_sec = 0;
* (__errno_location()) = EINTR;
return -1;
}
+
+ /* Sleeping finished. If a finite timeout, check to see if it
+ has expired yet. */
+ if (timeout) {
+ VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */,
+ VG_USERREQ__READ_MILLISECOND_TIMER,
+ 0, 0, 0, 0);
+ my_assert(ms_now != 0xFFFFFFFF);
+ if (ms_now >= ms_end) {
+ /* timeout; nothing interesting happened. */
+ if (rfds) FD_ZERO(rfds);
+ if (wfds) FD_ZERO(wfds);
+ if (xfds) FD_ZERO(xfds);
+ return 0;
+ }
+ }
+
}
}
/* Either timeout < 0, meaning wait indefinitely, or timeout > 0,
in which case t_end holds the end time. */
+
my_assert(__timeout != 0);
while (1) {
- if (__timeout > 0) {
- VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */,
- VG_USERREQ__READ_MILLISECOND_TIMER,
- 0, 0, 0, 0);
- my_assert(ms_now != 0xFFFFFFFF);
- if (ms_now >= ms_end) {
- /* timeout; nothing interesting happened. */
- for (i = 0; i < __nfds; i++)
- __fds[i].revents = 0;
- return 0;
- }
- }
/* Do a return-immediately poll. */
+
res = my_do_syscall3(__NR_poll, (int)__fds, __nfds, 0 );
if (is_kerror(res)) {
/* Some kind of error. Set errno and return. */
/* One or more fds is ready. Return now. */
return res;
}
+
+ /* Nothing interesting happened, so we go to sleep for a
+ while. */
+
/* fprintf(stderr, "MY_POLL: nanosleep\n"); */
/* nanosleep and go round again */
nanosleep_interval.tv_sec = 0;
is nonblocking. */
(void)my_do_syscall2(__NR_nanosleep,
(int)(&nanosleep_interval), (int)NULL);
+
+ /* Sleeping finished. If a finite timeout, check to see if it
+ has expired yet. */
+ if (__timeout > 0) {
+ VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */,
+ VG_USERREQ__READ_MILLISECOND_TIMER,
+ 0, 0, 0, 0);
+ my_assert(ms_now != 0xFFFFFFFF);
+ if (ms_now >= ms_end) {
+ /* timeout; nothing interesting happened. */
+ for (i = 0; i < __nfds; i++)
+ __fds[i].revents = 0;
+ return 0;
+ }
+ }
+
}
}
/* Either timeout == NULL, meaning wait indefinitely, or timeout !=
NULL, in which case ms_end holds the end time. */
+
while (1) {
- if (timeout) {
- VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */,
- VG_USERREQ__READ_MILLISECOND_TIMER,
- 0, 0, 0, 0);
- my_assert(ms_now != 0xFFFFFFFF);
- if (ms_now >= ms_end) {
- /* timeout; nothing interesting happened. */
- if (rfds) FD_ZERO(rfds);
- if (wfds) FD_ZERO(wfds);
- if (xfds) FD_ZERO(xfds);
- return 0;
- }
- }
+
+ /* First, do a return-immediately select(). */
/* These could be trashed each time round the loop, so restore
them each time. */
if (xfds) *xfds = xfds_copy;
return res;
}
+
+ /* Nothing interesting happened, so we go to sleep for a
+ while. */
+
/* fprintf(stderr, "MY_SELECT: nanosleep\n"); */
/* nanosleep and go round again */
nanosleep_interval.tv_sec = 0;
* (__errno_location()) = EINTR;
return -1;
}
+
+ /* Sleeping finished. If a finite timeout, check to see if it
+ has expired yet. */
+ if (timeout) {
+ VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */,
+ VG_USERREQ__READ_MILLISECOND_TIMER,
+ 0, 0, 0, 0);
+ my_assert(ms_now != 0xFFFFFFFF);
+ if (ms_now >= ms_end) {
+ /* timeout; nothing interesting happened. */
+ if (rfds) FD_ZERO(rfds);
+ if (wfds) FD_ZERO(wfds);
+ if (xfds) FD_ZERO(xfds);
+ return 0;
+ }
+ }
+
}
}
/* Either timeout < 0, meaning wait indefinitely, or timeout > 0,
in which case t_end holds the end time. */
+
my_assert(__timeout != 0);
while (1) {
- if (__timeout > 0) {
- VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */,
- VG_USERREQ__READ_MILLISECOND_TIMER,
- 0, 0, 0, 0);
- my_assert(ms_now != 0xFFFFFFFF);
- if (ms_now >= ms_end) {
- /* timeout; nothing interesting happened. */
- for (i = 0; i < __nfds; i++)
- __fds[i].revents = 0;
- return 0;
- }
- }
/* Do a return-immediately poll. */
+
res = my_do_syscall3(__NR_poll, (int)__fds, __nfds, 0 );
if (is_kerror(res)) {
/* Some kind of error. Set errno and return. */
/* One or more fds is ready. Return now. */
return res;
}
+
+ /* Nothing interesting happened, so we go to sleep for a
+ while. */
+
/* fprintf(stderr, "MY_POLL: nanosleep\n"); */
/* nanosleep and go round again */
nanosleep_interval.tv_sec = 0;
is nonblocking. */
(void)my_do_syscall2(__NR_nanosleep,
(int)(&nanosleep_interval), (int)NULL);
+
+ /* Sleeping finished. If a finite timeout, check to see if it
+ has expired yet. */
+ if (__timeout > 0) {
+ VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */,
+ VG_USERREQ__READ_MILLISECOND_TIMER,
+ 0, 0, 0, 0);
+ my_assert(ms_now != 0xFFFFFFFF);
+ if (ms_now >= ms_end) {
+ /* timeout; nothing interesting happened. */
+ for (i = 0; i < __nfds; i++)
+ __fds[i].revents = 0;
+ return 0;
+ }
+ }
+
}
}
/* Either timeout == NULL, meaning wait indefinitely, or timeout !=
NULL, in which case ms_end holds the end time. */
+
while (1) {
- if (timeout) {
- VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */,
- VG_USERREQ__READ_MILLISECOND_TIMER,
- 0, 0, 0, 0);
- my_assert(ms_now != 0xFFFFFFFF);
- if (ms_now >= ms_end) {
- /* timeout; nothing interesting happened. */
- if (rfds) FD_ZERO(rfds);
- if (wfds) FD_ZERO(wfds);
- if (xfds) FD_ZERO(xfds);
- return 0;
- }
- }
+
+ /* First, do a return-immediately select(). */
/* These could be trashed each time round the loop, so restore
them each time. */
if (xfds) *xfds = xfds_copy;
return res;
}
+
+ /* Nothing interesting happened, so we go to sleep for a
+ while. */
+
/* fprintf(stderr, "MY_SELECT: nanosleep\n"); */
/* nanosleep and go round again */
nanosleep_interval.tv_sec = 0;
* (__errno_location()) = EINTR;
return -1;
}
+
+ /* Sleeping finished. If a finite timeout, check to see if it
+ has expired yet. */
+ if (timeout) {
+ VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */,
+ VG_USERREQ__READ_MILLISECOND_TIMER,
+ 0, 0, 0, 0);
+ my_assert(ms_now != 0xFFFFFFFF);
+ if (ms_now >= ms_end) {
+ /* timeout; nothing interesting happened. */
+ if (rfds) FD_ZERO(rfds);
+ if (wfds) FD_ZERO(wfds);
+ if (xfds) FD_ZERO(xfds);
+ return 0;
+ }
+ }
+
}
}
/* Either timeout < 0, meaning wait indefinitely, or timeout > 0,
in which case t_end holds the end time. */
+
my_assert(__timeout != 0);
while (1) {
- if (__timeout > 0) {
- VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */,
- VG_USERREQ__READ_MILLISECOND_TIMER,
- 0, 0, 0, 0);
- my_assert(ms_now != 0xFFFFFFFF);
- if (ms_now >= ms_end) {
- /* timeout; nothing interesting happened. */
- for (i = 0; i < __nfds; i++)
- __fds[i].revents = 0;
- return 0;
- }
- }
/* Do a return-immediately poll. */
+
res = my_do_syscall3(__NR_poll, (int)__fds, __nfds, 0 );
if (is_kerror(res)) {
/* Some kind of error. Set errno and return. */
/* One or more fds is ready. Return now. */
return res;
}
+
+ /* Nothing interesting happened, so we go to sleep for a
+ while. */
+
/* fprintf(stderr, "MY_POLL: nanosleep\n"); */
/* nanosleep and go round again */
nanosleep_interval.tv_sec = 0;
is nonblocking. */
(void)my_do_syscall2(__NR_nanosleep,
(int)(&nanosleep_interval), (int)NULL);
+
+ /* Sleeping finished. If a finite timeout, check to see if it
+ has expired yet. */
+ if (__timeout > 0) {
+ VALGRIND_MAGIC_SEQUENCE(ms_now, 0xFFFFFFFF /* default */,
+ VG_USERREQ__READ_MILLISECOND_TIMER,
+ 0, 0, 0, 0);
+ my_assert(ms_now != 0xFFFFFFFF);
+ if (ms_now >= ms_end) {
+ /* timeout; nothing interesting happened. */
+ for (i = 0; i < __nfds; i++)
+ __fds[i].revents = 0;
+ return 0;
+ }
+ }
+
}
}