![]() |
![]() |
![]() |
Attach an event to an interrupt source
#include <sys/neutrino.h> int InterruptAttachEvent( int intr, const struct sigevent* event, unsigned flags ); int InterruptAttachEvent_r( int intr, const struct sigevent* event, unsigned flags );
libc
The InterruptAttachEvent() and InterruptAttachEvent_r() kernel calls attach the event to an interrupt specified by intr. They automatically enable (i.e unmask) the interrupt level.
The intr variable represents an interrupt vector number; see "Interrupt vector numbers" in the InterruptAttach() documentation for details.
Before calling this function, the thread must request I/O privity by calling:
ThreadCtl( _NTO_TCTL_IO, 0 );
If the thread doesn't do this, it might SIGSEGV when InterruptUnlock() is called.
To prevent infinite interrupt recursion, the kernel automatically does an InterruptMask() for intr when delivering the event. After the interrupt-handling thread has dealt with the event, it must call InterruptUnmask() to reenable the interrupt.
The event delivered when this interrupt occurs is a sigevent structure.
Consider the following when choosing an event type:
![]() |
The thread that calls InterruptWait() must be the one that called InterruptAttachEvent(). |
The flags argument is a bitwise OR of the following values, or 0:
Flag | Description |
---|---|
_NTO_INTR_FLAGS_END | Put the new event at the end of the list of existing events instead of the start. |
_NTO_INTR_FLAGS_PROCESS | Associate the event with the process instead of the attaching thread. |
_NTO_INTR_FLAGS_TRK_MSK | Track calls to InterruptMask() and InterruptUnmask() to make detaching the interrupt handler safer. |
The interrupt structure allows hardware interrupts to be shared. For example if two processes call InterruptAttachEvent() for the same physical interrupt, both events are sent consecutively. When an event attaches, it'll be placed in front of any existing events for that interrupt and be delivered first. This behavior can be changed by setting the _NTO_INTR_FLAGS_END flag in the flags argument. This adds the event at the end of any existing events.
Adding _NTO_INTR_FLAGS_PROCESS to flags associates the interrupt event with the process instead of the attaching thread. The interrupt event is removed when the process exits, instead of when the attaching thread exits.
![]() |
The kernel automatically attempts to set the _NTO_INTR_FLAGS_PROCESS flag if the event is directed at the process in general (for SIGEV_SIGNAL, SIGEV_SIGNAL_CODE, and SIGEV_PULSE events). |
The _NTO_INTR_FLAGS_TRK_MSK flag and the id argument to InterruptMask() and InterruptUnmask() let the kernel track the number of times a particular interrupt handler or event has been masked. Then, when an application detaches from the interrupt, the kernel can perform the proper number of unmasks to ensure that the interrupt functions normally. This is important for shared interrupt levels.
InterruptAttachEvent() has several advantages over InterruptAttach():
There are also some disadvantages:
You can freely mix calls to InterruptAttach() and InterruptAttachEvent() for a particular interrupt.
This call doesn't block.
An interrupt function ID; or -1 if an error occurs (errno is set).
Use this ID with the InterruptDetach() function to detach this interrupt event.
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
InterruptAttach(), InterruptDetach(), InterruptLock(), InterruptMask(), InterruptUnlock(), InterruptUnmask(), InterruptWait(), sigevent
![]() |
![]() |
![]() |