SignalWatcher is part of the CoCoA mechanism for detecting and
reacting to interprocess signals (sometimes known as "interrupts").
Since CoCoALib is a software library, it does not change any existing
signal handlers unless you tell to do so explicitly. A
is an RAII object: creating it installs CoCoA's "signal handler" for
the given signal; destroying it, reinstates the previous "signal
SignalWatcher by itself does not do much: it simply "takes note"
when a signal of the given type arrives. CoCoALib can react to a
signal only after it has been noted by a
CheckForInterrupt is called -- see
for a summary, or look at the example programs.
If several signals arrive before
CheckForInterrupt is called, only
the last signal is heeded; the others are "forgotten".
SignalWatcher(sig)-- install the standard CoCoALib signal handler for the signal
sig(usually this will be
SignalWatcher(sig, OtherHandler)-- install
OtherHandlerfor the signal
OtherHandleris of type
DESTRUCTOR-- the destructor reinstates the previous handler for the signal specified in the constructor
The exception which thrown when
CheckForInterrupt detects a signal is
created by the following constructor:
InterruptedBySignal(sig, context)-- where
intindicating the signal which has arrived, and
contextis a string literal (usually indicating the function which was interrupted)
SW be a
SWhas not been deactivated (see below)
GetAndResetSignalReceived()-- returns an
int: zero if no signal has arrived, otherwise the integer value of the signal. Resets the register of last-signal-received.
SW be of type
SignalWatcher; and let
INTR be of type
deactivate(SW)-- effectively "destroys"
SW, _i.e._ reinstates the previous signal handler
TriggeringSignal(INTR)-- returns an
intindicating the signal specified when creating
SetSignalReceived(sig)-- sets the register of last-signal-received to
sig; note that zero means no signal received. You probably should not use this function!
The implementation is straightforward (except for
which still involves a "dodgy hack" from an earlier implementation).
For portability the CoCoALib signal handler just sets
a "hidden" global variable
The CoCoALib signal handler is registered by creating an object
SignalWatcher; its constructor takes as arg the signal
to detect. The original signal is restored when the
is destroyed (or when the mem fn
myDeactivate is called).
I do not know how threadsafe the implementation is: hopefully it is good, but I doubt it is perfect.