#REFACTORING by stefan
class: ProcessorScheduler
changed:
#signal:after:
#signal:onInput:orCheck:
#signal:onInputStream:
#signal:onOutputStream:
use Logger
--- a/ProcessorScheduler.st Wed Mar 04 17:02:50 2020 +0100
+++ b/ProcessorScheduler.st Wed Mar 04 17:04:26 2020 +0100
@@ -2596,10 +2596,20 @@
"Modified: / 9.11.1998 / 20:39:06 / cg"
!
-signal:aSemaphore after:aTimeDuration
+signal:aSemaphore after:secondsOrTimeDuration
"arrange for a semaphore to be triggered after aTimeDuration"
- self signal:aSemaphore afterMilliseconds:aTimeDuration getMilliseconds
+ |ms|
+
+ secondsOrTimeDuration isTimeDuration ifTrue:[
+ ms := secondsOrTimeDuration getMilliseconds.
+ ] ifFalse:[
+ ms := (secondsOrTimeDuration * 1000) rounded.
+ ].
+
+ self signal:aSemaphore afterMilliseconds:ms.
+
+ "Modified: / 04-03-2020 / 14:32:10 / Stefan Vogel"
!
signal:aSemaphore afterMilliseconds:millis
@@ -2721,7 +2731,7 @@
If aBlock is nil, the semaphore is removed from the set of semaphores, after being signaled."
|idx "{ Class: SmallInteger }"
- wasBlocked slot|
+ wasBlocked slot readCheckEntry|
wasBlocked := OperatingSystem blockInterrupts.
@@ -2729,6 +2739,10 @@
aSemphore is never nil, but one of aFileDescriptor, aBlock may be nil"
aFileDescriptor isNil ifTrue:[
+ aBlock isNil ifTrue:[
+ wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+ self error:'Signalling requested for nil fd and nil block'.
+ ].
idx := readSemaphoreArray identityIndexOf:aSemaphore or:nil.
idx == 0 ifTrue:[
"aSemaphore is not registered yet, have to create a new slot"
@@ -2738,16 +2752,17 @@
] ifFalse:[
slot := readSemaphoreArray at:idx.
slot isNil ifTrue:[
+ "aSemaphore is not registered yet, found an empty slot"
readSemaphoreArray at:idx put:aSemaphore.
readCheckArray at:idx put:aBlock
] ifFalse:[
"/ someone has already registered aSemaphore.
"/ Check if it is the block changes...
- (readCheckArray at:idx) notNil ifTrue:[
- (readCheckArray at:idx) ~~ aBlock ifTrue:[
- 'Processor [info]: checkblock changed for read-check' infoPrintCR.
- readCheckArray at:idx put:aBlock.
- ].
+ readCheckEntry := readCheckArray at:idx.
+ (readCheckEntry notNil
+ and:[readCheckEntry ~~ aBlock]) ifTrue:[
+ Logger info:'Processor: checkblock changed for read-check'.
+ readCheckArray at:idx put:aBlock.
].
].
]
@@ -2761,6 +2776,7 @@
] ifFalse:[
slot := readFdArray at:idx.
slot isNil ifTrue:[
+ "aFileDescriptor is not registered yet, found an empty slot"
readFdArray at:idx put:aFileDescriptor.
readSemaphoreArray at:idx put:aSemaphore.
readCheckArray at:idx put:aBlock
@@ -2768,11 +2784,11 @@
"/ someone has already registered aFileDescriptor.
"/ Check if it is the semaphore or block changes...
(readSemaphoreArray at:idx) ~~ aSemaphore ifTrue:[
- 'Processor [info]: sema changed for read-check' infoPrintCR.
+ Logger info:'Processor: sema changed for read-check'.
readSemaphoreArray at:idx put:aSemaphore.
].
(readCheckArray at:idx) ~~ aBlock ifTrue:[
- 'Processor [info]: checkblock changed for read-check' infoPrintCR.
+ Logger info:'Processor: checkblock changed for read-check'.
readCheckArray at:idx put:aBlock.
].
].
@@ -2783,7 +2799,8 @@
].
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
- "Modified: 4.8.1997 / 15:20:45 / cg"
+ "Modified: / 04-08-1997 / 15:20:45 / cg"
+ "Modified (format): / 04-03-2020 / 14:12:10 / Stefan Vogel"
!
signal:aSemaphore onInputStream:aStream
@@ -2791,15 +2808,23 @@
This will do a select, if the OS supports selecting on that filedescriptor,
otherwise, it will be polled every few milliseconds (MSDOS)."
+ |fd|
+
+ fd := aStream fileHandle.
+ fd isNil ifTrue:[
+ aSemaphore signal.
+ ].
+
aStream canBeSelected ifTrue:[
"/ can this stream be selected on ?
- self signal:aSemaphore onInput:aStream fileHandle orCheck:nil
+ self signal:aSemaphore onInput:fd orCheck:nil
] ifFalse:[
"/ nope - must poll ...
self signal:aSemaphore onInput:nil orCheck:[aStream canReadWithoutBlocking]
]
- "Modified: / 14.12.1999 / 23:58:50 / cg"
+ "Modified: / 14-12-1999 / 23:58:50 / cg"
+ "Modified: / 04-03-2020 / 14:57:35 / Stefan Vogel"
!
signal:aSemaphore onOutput:aFileDescriptor
@@ -2892,15 +2917,23 @@
This will do a select, if the OS supports selecting on that filedescriptor,
otherwise, it will be polled every few milliseconds (MSDOS)."
+ |fd|
+
+ fd := aStream fileHandle.
+ fd isNil ifTrue:[
+ aSemaphore signal.
+ ].
+
aStream canBeSelected ifTrue:[
"/ can this stream be selected on ?
- self signal:aSemaphore onOutput:aStream fileHandle orCheck:nil
+ self signal:aSemaphore onOutput:fd orCheck:nil
] ifFalse:[
"/ nope - must poll ...
self signal:aSemaphore onOutput:nil orCheck:[aStream canWriteWithoutBlocking]
]
- "Modified: / 14.12.1999 / 23:59:19 / cg"
+ "Modified: / 14-12-1999 / 23:59:19 / cg"
+ "Modified: / 04-03-2020 / 14:58:05 / Stefan Vogel"
! !
!ProcessorScheduler methodsFor:'special configuration'!