- if (numFound != 0) {
- /*
- File descriptors ready, but we don't know how much time was spent
- in the select(). To interpolate, we compare the time before
- and after the select().
- */
+ /* Release the scheduler lock while we do the poll.
+ * this means that someone might muck with the blocked_queue
+ * while we do this, but it shouldn't matter:
+ *
+ * - another task might poll for I/O and remove one
+ * or more threads from the blocked_queue.
+ * - more I/O threads may be added to blocked_queue.
+ * - more delayed threads may be added to blocked_queue. We'll
+ * just subtract delta from their delays after the poll.
+ *
+ * I believe none of these cases lead to trouble --SDM.
+ */
+ RELEASE_LOCK(&sched_mutex);
+
+ /* Check for any interesting events */
+
+ tv.tv_sec = min / 1000000;
+ tv.tv_usec = min % 1000000;
+
+#ifndef linux_TARGET_OS
+ gettimeofday(&tv_before, (struct timezone *) NULL);
+#endif
+
+ while (!interrupted &&
+ (numFound = select(maxfd+1, &rfd, &wfd, NULL, &tv)) < 0) {
+ if (errno != EINTR) {
+ /* fflush(stdout); */
+ perror("select");
+ barf("select failed");
+ }
+ ACQUIRE_LOCK(&sched_mutex);
+
+ /* We got a signal; could be one of ours. If so, we need
+ * to start up the signal handler straight away, otherwise
+ * we could block for a long time before the signal is
+ * serviced.
+ */
+ if (signals_pending()) {
+ start_signal_handlers();
+ RELEASE_LOCK(&sched_mutex);
+ break;
+ }