care for nil arg in #waitWithTimeout:
authorClaus Gittinger <cg@exept.de>
Mon, 01 Oct 2001 22:53:45 +0200
changeset 6061 9e266783d5c2
parent 6060 d1e114791063
child 6062 c8b8b9d382f1
care for nil arg in #waitWithTimeout:
Semaphore.st
--- a/Semaphore.st	Fri Sep 28 19:01:04 2001 +0200
+++ b/Semaphore.st	Mon Oct 01 22:53:45 2001 +0200
@@ -638,6 +638,25 @@
      However, polling is not the intended use of semaphores, though.
      If seconds is nil, wait without timeout."
 
+    |millis|
+
+    seconds notNil ifTrue:[
+        millis := seconds * 1000 
+    ] ifFalse:[
+        millis := nil
+    ].
+    ^ self waitWithTimeoutMs:millis.
+!
+
+waitWithTimeoutMs:milliSeconds
+    "wait for the semaphore, but abort the wait after some time.
+     return the receiver if the semaphore triggered normal, nil if we return
+     due to a timeout. 
+     With zero timeout, this can be used to poll a semaphore (returning
+     the receiver if the semaphore is available, nil if not).
+     However, polling is not the intended use of semaphores, though.
+     If milliSeconds is nil, wait without timeout."
+
     |activeProcess timeoutOccured wasBlocked unblock now endTime|
 
     "
@@ -658,7 +677,7 @@
     "
      with zero-timeout, this is a poll
     "
-    seconds = 0 ifTrue:[
+    milliSeconds = 0 ifTrue:[
         ^ nil
     ].
 
@@ -669,9 +688,9 @@
     "
      calculate the end-time
     "
-    seconds notNil ifTrue:[
+    milliSeconds notNil ifTrue:[
         now := OperatingSystem getMillisecondTime.
-        endTime := OperatingSystem millisecondTimeAdd:now and:(seconds * 1000).
+        endTime := OperatingSystem millisecondTimeAdd:now and:milliSeconds.
 
         unblock := [timeoutOccured := true. Processor resume:activeProcess].
         Processor addTimedBlock:unblock for:activeProcess atMilliseconds:endTime.
@@ -726,5 +745,5 @@
 !Semaphore class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Semaphore.st,v 1.59 2000-11-16 11:16:59 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Semaphore.st,v 1.60 2001-10-01 20:53:45 cg Exp $'
 ! !