int32 AllocSignal( uint32 sigMask )
Tasks that send and receive signals must agree on which signal bits to use and the meanings of the signals. Except for system signals, there are no conventions for the meanings of individual signal bits; it is up to software developers to define their meanings.
You allocate bits for new signals by calling AllocSignal()
. To define one signal at a time - by far the most common case - call AllocSignal()
with 0 as the argument:
theSignal = AllocSignal( 0 )
This allocates the next unused bit in the signal word. In the return value, the bit that was allocated is set. If the allocation fails (which happens if all the non-reserved bits in the signal word are already allocated), the procedure returns 0.
In rare cases, you may need to define more than one signal with a single call. You do this by creating a uint32 value and setting any bits you want to allocate for new signals, then calling AllocSignal()
with this value as the argument. If all the signals are successfully allocated, the bits set in the return value are the same as the bits that were set in the argument.
Signals are implemented as follows:
AllocSignal()
. The bits are numbered from 0 (the least-significant bit) to 31 (the most-significant bit). Bits 0 through 7 are reserved for system signals (signals sent by the kernel to all tasks); remaining bits can be allocated for other signals. Note: Bit 31 is also reserved for the system. It is set when the kernel returns an error code to a task instead of signals. For example, trying to allocate a system signal or signal number 31.
SendSignal()
to send one or more signals to another task. Each bit set in the signalWord argument specifies a signal to send. Normally, only one signal is sent at a time.
SendSignal()
is called, the kernel gets the incoming signal word and ORs it into the received signal mask of the target task. If the task was in the wait queue, it compares the received signals with the WaitSignalMask. If there are any bits set in the target, the task is moved from the wait queue to the ready queue.
WaitSignal()
. If any bits are set in the task's signal word , WaitSignal()
returns immediately. If no bits are set in the task's signal word, the task remains in wait state until a signal arrives that matches one of the signals the task is waiting for.
FreeSignal()
to deallocate signals. Future versions of Portfolio may define additional system signals. To help ensure that the signal bits you allocate in current applications do not conflict with future system signals, you should always use 0 as the value of the signalMask argument when allocating signals. If you must allocate specific signal bits (which is discouraged), use bits 17-31.
FreeSignal
(), GetCurrentSignals(), SendSignal(), WaitSignal()