poll_for_read_fds(): don't waste time calling select() if there are
no waiting fds.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@60 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/vg_scheduler.c b/vg_scheduler.c
index ff1697c..ecf4466 100644
--- a/vg_scheduler.c
+++ b/vg_scheduler.c
@@ -42,16 +42,14 @@
 
 - properly save scheduler private state in signal delivery frames.
 
-- fd-poll optimisation (don't select with empty sets)
-
 - signals interrupting read/write and nanosleep, and take notice
   of SA_RESTART or not
 
 - when a thread is done mark its stack as noaccess 
 
-- make signal return and .fini call be detected via request mechanism
+- 0xDEADBEEF syscall errors ... fix.
 
- */
+*/
 
 
 /* ---------------------------------------------------------------------
@@ -688,10 +686,11 @@
    Bool               rd_ok, wr_ok, ex_ok;
    Char               msg_buf[100];
 
+   struct vki_timespec* rem;
+   ULong                t_now;
+
    /* Awaken any sleeping threads whose sleep has expired. */
-   {
-   struct vki_timespec * rem;
-   ULong t_now = VG_(read_microsecond_timer)();
+   t_now = VG_(read_microsecond_timer)();
    for (tid = 0; tid < VG_N_THREADS; tid++) {
       if (vg_threads[tid].status != VgTs_Sleeping)
          continue;
@@ -715,8 +714,9 @@
          }
       }
    }
-   }
 
+   /* And look for threads waiting on file descriptors which are now
+      ready for I/O.*/
    timeout.tv_sec = 0;
    timeout.tv_usec = 0;
 
@@ -731,6 +731,7 @@
          continue;
       fd = vg_waiting_fds[i].fd;
       /* VG_(printf)("adding QUERY for fd %d\n", fd); */
+      vg_assert(fd >= 0);
       if (fd > fd_max) 
          fd_max = fd;
       tid = vg_waiting_fds[i].tid;
@@ -748,6 +749,10 @@
       }
    }
 
+   /* Short cut: if no fds are waiting, give up now. */
+   if (fd_max == -1)
+      return;
+
    /* BLOCK ALL SIGNALS.  We don't want the complication of select()
       getting interrupted. */
    VG_(block_all_host_signals)( &saved_procmask );