changeset 281:fc52fa818b5f

* src/select.cxx (select): Changed mechanism for calculating select timeout to avoid possible race conditions between this code and the timer DSR.
author nickg
date Fri, 09 Aug 2002 17:10:21 +0000
parents 96e3418e1f5b
children a29ee6c2dd3c
files packages/io/fileio/current/ChangeLog packages/io/fileio/current/src/select.cxx
diffstat 2 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/packages/io/fileio/current/ChangeLog
+++ b/packages/io/fileio/current/ChangeLog
@@ -1,3 +1,9 @@
+2002-08-08  Nick Garnett  <nickg@calivar.demon.co.uk>
+
+	* src/select.cxx (select): Changed mechanism for calculating
+	select timeout to avoid possible race conditions between this code
+	and the timer DSR.
+
 2002-05-29  Jesper Skov  <jskov@redhat.com>
 
 	* tests/fileio1.c: Removed strcat definition. Rely on string.h to
--- a/packages/io/fileio/current/src/select.cxx
+++ b/packages/io/fileio/current/src/select.cxx
@@ -162,8 +162,7 @@ select(int nfd, fd_set *in, fd_set *out,
 
     // Compute end time
     if (tv)
-        ticks = Cyg_Clock::real_time_clock->current_value() +
-            cyg_timeval_to_ticks( tv );
+        ticks = cyg_timeval_to_ticks( tv );
     else ticks = 0;
 
     // Lock the mutex
@@ -226,11 +225,14 @@ select(int nfd, fd_set *in, fd_set *out,
                     FILEIO_RETURN_VALUE(0);
                 }
 
+                ticks += Cyg_Clock::real_time_clock->current_value();
+                
                 if( !selwait.wait( ticks ) )
                 {
                     // A non-standard wakeup, if the current time is equal to
                     // or past the timeout, return zero. Otherwise return
                     // EINTR, since we have been released.
+
                     if( Cyg_Clock::real_time_clock->current_value() >= ticks )
                     {
                         select_mutex.unlock();
@@ -239,6 +241,8 @@ select(int nfd, fd_set *in, fd_set *out,
                     }
                     else error = EINTR;
                 }
+
+                ticks -= Cyg_Clock::real_time_clock->current_value();
             }
             else
             {