NKAcquireOalSpinLock (Compact 2013)
3/28/2014
This function acquires an OEM adaptation layer (OAL) spin lock to protect shared resources.
Syntax
void
NKAcquireOalSpinLock
(void)
Parameters
None.
Return Value
None.
Remarks
In a single-processor environment, resources accessed in an ISR are typically protected by turning interrupts off. This does not work when there is more than one processor, as other processors can be running conflicting function calls at the same time.
Since it is not possible to use a critical section in an ISR context, the only way to protect shared resources is by spin lock. Use this function to protect shared resource in an ISR context, rather than turning interrupts off.
The OAL spin lock has the following limitations:
- Maximum stack usage is less than 2048 bytes.
- You cannot use other synchronization objects while you own the spin lock because you cannot block while interrupts are turned off.
- You cannot issue any debug messages going through the kernel independent transport layer (KITL) or kernel while spin lock is applied.
Note
You can also use OAL spin lock on single-processor systems. However, other synchronization objects will often provide better performance on single-processor systems.
Holding a spinlock prevents threads from being rescheduled. Do not write code that holds a spin lock while running routines that can take indeterminate amounts of time. This could potentially cause all processors to spin and do nothing while waiting for the spin lock to be released. Break your code into small, non-pre-emptible chunks and use the OAL spin lock only to guard those small chunks of code.
Requirements
Header |
nkglobal.h |
Library |
Nkstub.lib |
See Also
Reference
SMP Functions
NKReleaseOalSpinLock
NKSendInterProcessorInterrupt