diff packages/kernel/current/src/sync/cnt_sem.cxx @ 1062:e8b69d9c90a6

* cdl/kernel.cdl: Added tests/bin_sem3 to list of kernel tests. * include/sema.hxx: Added declaration for wait with timeout for Cyg_Binary_Semaphore. * include/instrmnt.h: Added instrumentation point for binary semaphore timeout. * src/sync/bin_sem.cxx: Added wait with time-out function to Cyg_Binary_Semaphore class. * src/sync/cnt_sem.cxx: Modified semantics slightly to claim an available semaphore even with a timeout in the past. This is in line with the new timed wait in bin_sem.cxx. * tests/bin_sem3.cxx: Created new test for timed wait binary semaphore.
author nickg
date Mon, 23 Jun 2003 18:09:59 +0000
parents d2c90368aeef
children 74dbf4c3f2e1
line wrap: on
line diff
--- a/packages/kernel/current/src/sync/cnt_sem.cxx
+++ b/packages/kernel/current/src/sync/cnt_sem.cxx
@@ -156,10 +156,12 @@ Cyg_Counting_Semaphore::wait( cyg_tick_c
     self->set_timer( timeout, Cyg_Thread::TIMEOUT  );
 
     // If the timeout is in the past, the wake reason will have been
-    // set to something other than NONE already. Set the result false
-    // to force an immediate return.
+    // set to something other than NONE already. If the count is zero,
+    // set the result false to force an immediate return. If the count
+    // is non-zero, then this wait will succeed anyway.
     
-    if( self->get_wake_reason() != Cyg_Thread::NONE )
+    if( self->get_wake_reason() != Cyg_Thread::NONE &&
+        0 == count )
         result = false;
             
     while ( 0 == count && result ) {