InterruptLock()

QNX SDP8.0C Library ReferenceAPIDeveloper

Attempt to acquire a spinlock with interrupts disabled

Synopsis:

#include <sys/neutrino.h>

void InterruptLock( intrspin_t* spinlock );

Arguments:

spinlock
The spinlock 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. Before calling this function:

  • The process must have the PROCMGR_AID_IO ability enabled. For more information, see procmgr_ability().
  • The calling thread must have obtained I/O privileges by calling:
    ThreadCtl( _NTO_TCTL_IO_LEVEL, (void*)_NTO_IO_LEVEL_1 );
    

If you don't do these things, the thread might SIGSEGV when it calls InterruptLock().

This function tries to acquire the spinlock 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 );

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

Note:
  • You should disable interrupts for as little time as possible (i.e., the minimum time you need to access or deal with the hardware). Failure to do so may result in increased interrupt latency and the inability to meet realtime deadlines.
  • Some kernel calls and library routines reenable interrupts. Masked interrupts aren't affected.
  • This function doesn't support nesting. If a specific thread calls InterruptLock() multiple times with different spinlocks and then calls InterruptUnlock() the same number of times and in reverse order with the locks, the first InterruptUnlock() call reenables interrupts and the critical section is no longer protected.

Classification:

QNX OS

Safety:
Cancellation pointNo
Signal handlerYes
ThreadYes
Page updated: