Spinlock
XWOS spinlock
2 minute read
A critical section refers to a code fragment that accesses shared resources. In traditional RTOS, the following methods are commonly used to protect critical section resources:
The XWOS kernel is designed for MP systems (UP can be viewed as a special case of MP), so the approach to entering a critical section differs somewhat from traditional RTOS:
lock and unlock forms of the API from spinlock or its derived locks;lock_cpuirq and unlock_cpuirq forms of the API from spinlock or its derived locks. If accessing a critical section requires acquiring multiple spinlocks or their derived locks, use the lock_cpuirqsv and unlock_cpuirqrs forms of the API to save and restore the CPU interrupt enable flag, preventing the inner lock from accidentally re-enabling CPU interrupts upon unlock;lock_irqs and unlock_irqs forms of the API from spinlock or its derived locks. If accessing a critical section requires acquiring multiple spinlocks or their derived locks, use the lock_irqssv and unlock_irqsrs forms of the API to save and restore partial interrupt enable flags, preventing the inner lock from accidentally re-enabling these interrupts upon unlock;lock_bh and unlock_bh forms of the API from spinlock or its derived locks;xwos/lib/xwaop.h, and abstracts a memory model similar to std:atomic.