Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/i/interruptlock.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/i/interruptlock.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/i/interruptlock.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/i/interruptlock.html on line 8

InterruptLock()

Guard a critical section in an interrupt handler

Synopsis:

#include <sys/neutrino.h>

void InterruptLock( intrspin_t* spinlock );

Arguments:

spinlock
The spinlock (a variable shared between the interrupt handler and a thread) to use.

Note: If spinlock isn't a static variable, you must initialize it by calling:
memset( spinlock, 0, sizeof( *spinlock ) );
  

before using it with InterruptLock().


Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The InterruptLock() function guards a critical section by locking the specified spinlock. You can call this function from a thread or from an interrupt handler. Before calling this function, the thread must request I/O privileges by calling:

ThreadCtl( _NTO_TCTL_IO, 0 );

If the thread doesn't do this, it might SIGSEGV when it calls InterruptLock().

This function tries to acquire the spinlock (a variable shared between the interrupt handler and a thread) while interrupts are disabled. The code spins in a tight loop until the lock is acquired. It's important to release the lock as soon as possible. Typically, this is a few lines of code without any loops:

InterruptLock( &spinner );

/* ... critical section */

InterruptUnlock( &spinner );

InterruptLock() solves a common need in many realtime systems to protect access to shared data structures between an interrupt handler and the thread that owns the handler. The traditional POSIX primitives used between threads aren't available for use by an interrupt handler.

The InterruptLock() and InterruptUnlock() functions work on single-processor or multiprocessor machines.


Note: Any kernel call results in the re-enabling of interrupts, and many library routines are built on kernel calls. Masked interrupts are not affected.

Classification:

QNX Neutrino

Safety:
Cancellation point No
Interrupt handler Yes
Signal handler Yes
Thread Yes

See also:

InterruptDisable(), InterruptEnable(), InterruptMask(), InterruptUnlock(), InterruptUnmask(), ThreadCtl()

Writing an Interrupt Handler chapter of the Neutrino Programmer's Guide

Interrupts chapter of Getting Started with QNX Neutrino


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/i/interruptlock.html on line 187

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/i/interruptlock.html on line 187