--- a/Semaphore.st Tue Oct 12 16:50:50 1999 +0200
+++ b/Semaphore.st Tue Oct 12 18:23:22 1999 +0200
@@ -625,7 +625,8 @@
The seconds-argument may be a float (i.e. use 0.1 for a 100ms 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."
+ However, polling is not the intended use of semaphores, though.
+ If seconds is nil, wait without timeout."
|activeProcess timeoutOccured wasBlocked unblock now endTime|
@@ -637,18 +638,18 @@
things will go mad ... (especially be careful when adding a debugPrint-here)
"
count ~~ 0 ifTrue:[
- count := count - 1.
- count == 0 ifTrue:[
- lastOwnerID := Processor activeProcessId.
- ].
- ^ self
+ count := count - 1.
+ count == 0 ifTrue:[
+ lastOwnerID := Processor activeProcessId.
+ ].
+ ^ self
].
"
with zero-timeout, this is a poll
"
seconds = 0 ifTrue:[
- ^ nil
+ ^ nil
].
activeProcess := Processor activeProcess.
@@ -658,11 +659,13 @@
"
calculate the end-time
"
- now := OperatingSystem getMillisecondTime.
- endTime := OperatingSystem millisecondTimeAdd:now and:(seconds * 1000).
+ seconds notNil ifTrue:[
+ now := OperatingSystem getMillisecondTime.
+ endTime := OperatingSystem millisecondTimeAdd:now and:(seconds * 1000).
- unblock := [timeoutOccured := true. Processor resume:activeProcess].
- Processor addTimedBlock:unblock for:activeProcess atMilliseconds:endTime.
+ unblock := [timeoutOccured := true. Processor resume:activeProcess].
+ Processor addTimedBlock:unblock for:activeProcess atMilliseconds:endTime.
+ ].
"
need a while-loop here, since more than one process may
@@ -671,34 +674,37 @@
suspend.
"
[count == 0] whileTrue:[
- waitingProcesses add:activeProcess.
+ waitingProcesses add:activeProcess.
- timeoutOccured := false.
- "
- for some more descriptive info in processMonitor ...
- ... set the state to #wait (instead of #suspend)
- "
- [
- activeProcess suspendWithState:#wait.
- ] valueOnUnwindDo:[
- unblock := nil.
- waitingProcesses removeIdentical:activeProcess ifAbsent:[].
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
- ].
+ timeoutOccured := false.
+ "
+ for some more descriptive info in processMonitor ...
+ ... set the state to #wait (instead of #suspend)
+ "
+ [
+ activeProcess suspendWithState:#wait.
+ ] valueOnUnwindDo:[
+ unblock := nil.
+ waitingProcesses removeIdentical:activeProcess ifAbsent:[].
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ ].
- waitingProcesses removeIdentical:activeProcess ifAbsent:[].
- timeoutOccured ifTrue:[
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
- unblock := nil.
- ^ nil
- ].
+ waitingProcesses removeIdentical:activeProcess ifAbsent:[].
+ timeoutOccured ifTrue:[
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ unblock := nil.
+ ^ nil
+ ].
].
- Processor removeTimedBlock:unblock.
- unblock := nil.
+
+ unblock notNil ifTrue:[
+ Processor removeTimedBlock:unblock.
+ unblock := nil.
+ ].
count := count - 1.
count == 0 ifTrue:[
- lastOwnerID := Processor activeProcessId.
+ lastOwnerID := Processor activeProcessId.
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
^ self
@@ -710,5 +716,5 @@
!Semaphore class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Semaphore.st,v 1.55 1999-08-25 16:21:24 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Semaphore.st,v 1.56 1999-10-12 16:23:22 cg Exp $'
! !