NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | ERRORS | RESTRICTIONS | ATTRIBUTES
#include <sync/chSpinLock.h>void svMaskedLockInit(KnMaskedSpinLock * lockaddr, KnMaskedSpinLockInfo * info);
Spin locks are mutual exclusion objects, used to protect very short critical sections. These critical sections must not include kernel calls and the data they manipulate must be locked in memory to avoid page faults.
In multiprocessor systems, threads loop actively when resources are not available. A spin lock is an object in memory, typically modified and checked through indivisible machine operations (such as test-and-set).
In monoprocessor systems, spin locks are implemented by disabling preemption or interrupts.
Note that while a thread is holding a spin lock, a masked spin lock, or has disabled preemption, it is no longer allowed to block. In this case, the list of system calls available to the thread is restricted to the following:
semV threadSemPost eventPost msgPut svSpinLockGet svSpinLockRel svMaskedLockGet svMaskedLockRel svMaskAll svUnmaskAll svUnmask svPreemptable svIntrLevel svTimeoutSet svTimeoutCancel svPagesAllocate |
The system not force the thread to restrict itself to the permitted calls. If the thread issues non-permitted calls, the system will hang.
The svMaskedLockInit and svSpinLockInit functions initialize a spin lock in the free state. The info argument allows the user to enforce lock hierarchy and/or to gather lock use/contention statistics in the future.
In multiprocessor systems, svMaskedLockGet atomically disables interrupts on the current processor and acquires a spin lock. This routine spins actively on the lock value until it becomes free. Note that spinning is performed with interrupts enabled to reduce interrupt latency. This function can be called from within an interrupt handler.
The svMaskedLockTry function attempts to acquire a spin lock, but returns immediately without spinning if there is none available. This function can be called from an interrupt handler.
The svMaskedLockRel function releases a spin lock and re-enables interrupts on the current processor. This function can be called from within an interrupt handler.
The svMaskedLockGet, svMaskedLockTry and svMaskedLockRel functions only relate to the interrupt mask of the current processor, and do not affect interrupt processing on other processors. If the machine is equipped with an external interrupt controller, these calls have no effect on the controller status.
In multiprocessor systems, svSpinLockGet atomically disables preemption on the current processor and acquires a spin lock. This routine spins actively on the lock value until it becomes free. Note that spinning is performed with preemption enabled to reduce scheduling latency. On a monoprocessor, svSpinLockGet disables preemption on the current processor. This function cannot be called from within an interrupt handler.
The svSpinLockTry try attempts to acquire a spin lock, returning immediately without spinning if there is none available. This function cannot be called from within an interrupt handler.
The svSpinLockRel function releases a spin lock. This function ca not be called from within an interrupt handler.
If the current thread is preemptable, svPreemptable returns a non-zero value, otherwise it returns zero.
If called from an interrupt level, svIntrLevel returns a non-zero value, otherwise it returns zero.
If the lock is successfully acquired, svSpinLockTry returns the previous state of the lock (K_AVAIL). The svMaskedLockTry function returns K_AVAIL. The svPreemptable and svIntrLevel calls return a value which depends on the current execution context. Other calls return 0.
No error codes are returned. In DEBUG mode, the kernel debugger is invoked if the lock level hierarchy is violated, or if a spin lock cannot be acquired after a very large number of iterations, indicating a probable deadlock.
Hierarchy level checks are not performed in this version.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
---|---|
Interface Stability | Evolving |
NAME | SYNOPSIS | DESCRIPTION | RETURN VALUE | ERRORS | RESTRICTIONS | ATTRIBUTES