Structure that describes an event
#include <sys/siginfo.h> union sigval { int sival_int; void *sival_ptr; }; struct sigevent { int sigev_notify; union { int __sigev_signo; int __sigev_coid; int __sigev_id; void (*__sigev_notify_function)(union sigval); volatile unsigned *__sigev_addr; } __sigev_un1; # define sigev_signo __sigev_un1.__sigev_signo # define sigev_coid __sigev_un1.__sigev_coid # define sigev_id __sigev_un1.__sigev_id # define sigev_notify_function __sigev_un1.__sigev_notify_function # define sigev_addr __sigev_un1.__sigev_addr union sigval sigev_value; union { struct { short __sigev_code; short __sigev_priority; } __st; pthread_attr_t *__sigev_notify_attributes; int __sigev_memop; } __sigev_un2; # define sigev_notify_attributes __sigev_un2.__sigev_notify_attributes # define sigev_code __sigev_un2.__st.__sigev_code # define sigev_priority __sigev_un2.__st.__sigev_priority # define sigev_memop __sigev_un2.__sigev_memop };
This structure describes an event. POSIX specifies the basic structure and allows a lot of leeway in extending it. It effectively includes these members (although they aren't all usable at the same time):
Member | Classification |
---|---|
int sigev_notify | POSIX |
int sigev_signo | POSIX |
int sigev_coid | QNX Neutrino |
int sigev_id (not currently used) | QNX Neutrino |
void sigev_notify_function | POSIX |
volatile unsigned *sigev_addr | QNX Neutrino |
union sigval sigev_value | POSIX |
short sigev_code | QNX Neutrino |
short sigev_priority | QNX Neutrino |
pthread_attr_t *sigev_notify_attributes | POSIX |
int sigev_memop | QNX Neutrino |
The value of sigev_notify indicates how the notification is to occur and which of the other members are used:
SIGEV_SET_TYPE(&my_event, SIGEV_PULSE)
If you want to test the value of this member, use the SIGEV_GET_TYPE() macro. For example, instead of:
if( my_event.sigev_notify == SIGEV_PULSE)
use:
if( SIGEV_GET_TYPE(&my_event) == SIGEV_PULSE)
The <sys/siginfo.h> file also defines some macros to make initializing the sigevent structure easier. All the macros take a pointer to a sigevent structure as their event argument and set the sigev_notify member to the appropriate value. These macros are QNX Neutrino extensions and are described below.
SIGEV_INTR (QNX Neutrino extension)
Send an interrupt notification to a specific thread. No other fields in the structure are used.
The initialization macro is:
SIGEV_INTR_INIT( &event )
SIGEV_MEMORY (QNX Neutrino extension)
(QNX Neutrino 6.6 or later) Directly manipulate a location in memory. The following fields are used:
For the SIGEV_MEM_BIT* operations, the bits that are set in the value indicate which bits to set, clear, or toggle in the location in memory.
The initialization macro is:
SIGEV_MEMORY_INIT( &event, addr, value, operation )
One use for this type of event is to indicate when a local cache has been invalidated. For example, confstr(CS_TIMEZONE, ...) is called a lot, but the time zone hardly ever changes. You can call it once, cache the result, and then use procmgr_event_notify_add() like this:
procmgr_event_notify_add( PROCMGR_EVENT_CONFSTR, my_sigevent);
to notify the client by setting a memory location when the time zone string might have changed. If somebody wants to get the time zone, and the memory location hasn't been set, the local cached value is still current. If the memory location is set, you need to call confstr(CS_TIMEZONE, ...) again.
SIGEV_NONE (POSIX)
Don't send any notification. No other fields in the structure are used.
The initialization macro is:
SIGEV_NONE_INIT( &event )
SIGEV_PULSE (QNX Neutrino extension)
Send a pulse. The following fields are used:
The priority of the pulse must be in the range for the target process, or (in QNX Neutrino 6.6 or later) that process must have the PROCMGR_AID_PRIORITY ability enabled (see procmgr_ability()). In QNX Neutrino 6.6 or later, if procnto was started with an "s" appended to the -P option, then out-of-range priority requests use the maximum allowed value instead of resulting in an error.
The initialization macro is:
SIGEV_PULSE_INIT( &event, coid, priority, code, value )
SIGEV_SIGNAL (POSIX)
Send a signal to a process. The following fields are used:
The initialization macro is:
SIGEV_SIGNAL_INIT( &event, signal )
If you need to set the sigev_value for a SIGEV_SIGNAL event (for example if SA_SIGINFO is set), you can use this macro:
SIGEV_SIGNAL_VALUE_INIT( &event, signal, value )
SIGEV_SIGNAL_CODE (QNX Neutrino extension)
This is similar to SIGEV_SIGNAL, except that SIGEV_SIGNAL_CODE also includes a value and a code. The following fields are used:
The initialization macro is:
SIGEV_SIGNAL_CODE_INIT( &event, signal, value, code )
SIGEV_SIGNAL_THREAD (QNX Neutrino extension)
Send a signal to a specific thread, depending on the situation:
In the case of timers, SyncMutexEvent(), and interrupts, if the thread dies before the event gets delivered, the kernel sends the signal to a random thread in the same process.
The following fields are used:
The initialization macro is:
SIGEV_SIGNAL_THREAD_INIT( &event, signal, value, code )
SIGEV_THREAD (POSIX)
Create a new thread.
The following fields are used:
The initialization macro is:
SIGEV_THREAD_INIT( &event, fn, value, attr )
The sigval union is defined as follows:
union sigval { int sival_int; void * sival_ptr; };
SIGEV_UNBLOCK (QNX Neutrino extension)
Force a thread to become unblocked. No other fields in the structure are used.
The initialization macro is:
SIGEV_UNBLOCK_INIT( &event )
Hidden bits (QNX Neutrino extension)
After you've set up the sigevent structure as appropriate, you can use some extra bits in sigev_notify for other purposes. The bits and their associated macros include:
The receiving thread doesn't have to do anything to make itself critical or noncritical; the adaptive partitioning scheduler does this automatically. For more information, see the Adaptive Partitioning User's Guide.
The actual update depends on the server. For information about the updated information for kernel events, see procmgr_event_notify_add().
if (event.sigev_notify & SIGEV_FLAG_UPDATEABLE) { // may update event before delivering } else { // should not update event before delivering }