Use Semaphore>>waitWithTimeoutMs:state: instead of copy'paste version of waitWithTimeoutMs:
--- a/extensions.st Fri Jun 13 15:46:39 2014 +0100
+++ b/extensions.st Wed Jun 25 11:03:47 2014 +0100
@@ -307,7 +307,7 @@
nm := nm copyFrom: 2 to: nm size - 1.
(nm includes: $/) ifTrue: [
"/ No need to do another copt here!!
- nm replaceAll: $/ with: $.
+ nm replaceAll: $/ with: $.
].
] ifFalse:[
(nm includes: $/) ifTrue: [
@@ -1455,84 +1455,9 @@
!Semaphore methodsFor:'waiting'!
parkWithTimeoutMs:milliSeconds
- "Same as #waitWithTimeoutMs: but sets the state to #parked.
-
- Stupid, that I have to copy-paste this method...
- "
-
- |activeProcess timeoutOccured wasBlocked timeoutBlock now endTime|
-
- wasBlocked := OperatingSystem blockInterrupts.
-
- count <= 0 ifTrue:[
- "with zero-timeout, this is a poll"
- milliSeconds == 0 ifTrue:[
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
- ^ nil
- ].
-
- activeProcess := Processor activeProcess.
- timeoutOccured := false.
-
- milliSeconds notNil ifTrue:[
- "Wait with timeout: calculate the end-time"
- now := OperatingSystem getMillisecondTime.
- endTime := OperatingSystem millisecondTimeAdd:now and:milliSeconds.
-
- timeoutBlock := [timeoutOccured := true. timeoutBlock:= nil. Processor resume:activeProcess].
- Processor addTimedBlock:timeoutBlock for:activeProcess atMilliseconds:endTime.
- ].
-
- "
- need a while-loop here, since more than one process may
- wait for it and another one may also wake up.
- Thus, the count is not always non-zero after returning from
- suspend.
- "
- [
- self addWaitingProcess:activeProcess.
-
- "
- for some more descriptive info in processMonitor ...
- ... set the state to #wait (instead of #suspend)
- "
- [
- "sleep until resumed..."
- activeProcess suspendWithState:#parked.
- ] ifCurtailed:[
- "interrupts are not blocked when entered through Processor>>#interruptActive"
- OperatingSystem blockInterrupts.
- timeoutBlock notNil ifTrue:[
- Processor removeTimedBlock:timeoutBlock.
- timeoutBlock := nil.
- ].
- self removeWaitingProcess:activeProcess.
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
- ].
-
- self removeWaitingProcess:activeProcess.
- timeoutOccured ifTrue:[
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
- ^ nil
- ].
- ] doUntil:[count > 0].
-
- timeoutBlock notNil ifTrue:[
- Processor removeTimedBlock:timeoutBlock.
- timeoutBlock := nil.
- ].
- ].
-
- "if we come here, we have accquired the semaphore"
- count := count - 1.
- count == 0 ifTrue:[
- activeProcess isNil ifTrue:[activeProcess := Processor activeProcess].
- lastOwner := activeProcess.
- ].
- wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
- ^ self
-
- "Created: / 16-08-2012 / 20:53:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Same as #waitWithTimeoutMs: but sets the state to #parked."
+
+ ^ self waitWithTimeoutMs:milliSeconds state: #parked
! !
!Set methodsFor:'javaProtocol'!