|
Class: EventSemaphore
Object
|
+--AbstractLock
|
+--Semaphore
|
+--EventSemaphore
- Package:
- stx:libbasic
- Category:
- Kernel-Processes
- Version:
- rev:
1.9
date: 2021/01/20 12:58:21
- user: cg
- file: EventSemaphore.st directory: libbasic
- module: stx stc-classLibrary: libbasic
Processes wait for an EventSemaphores until it is signaled.
The EventSemaphore is not consumed and remains signaled until manually reset.
copyrightCOPYRIGHT (c) 2016 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
exampleCreate an event and signal it.
After being signaled, the waiter on the event returns immediately.
[exBegin]
|event|
event := EventSemaphore new.
[ event wait. Transcript showCR:'Process 1 continued' ] forkAt:9.
[ event wait. Transcript showCR:'Process 2 continued' ] forkAt:9.
event signal.
event wait.
event wait.
[exEnd]
signaling
-
new: n
-
count must be 0 or 1
blocked
-
signalForAll
-
blocked, since it would only set the event if there was anyone waiting
-
signalIf
-
blocked, since it would only set the event if there was anyone waiting
misc
-
reset
-
reset the event to the non-signaled state
semaphoreSet interface
-
checkAndAddWaitingProcess: process
-
interface for SemaphoreSet.
If the semaphore is available, return true.
Otherwise register our process to be wakened up once the semaphore is available
and return false.
ATTENTION: this must be invoked with OperatingSystem-interrupts-blocked.
signaling
-
signal
-
redefined to limit count to 1
waiting
-
wait
-
once signaled, do not decrement the count
-
waitWithTimeoutMs: milliSeconds state: newState
-
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.
Redefined: once signaled, do not decrement the count
|