Spinlocks, Scheduler lock – Comtrol eCos User Manual
Page 299
Chapter 9. HAL Interfaces
Spinlocks
Spinlocks provide inter-CPU locking. Normally they will be implemented on top of the test-and-set mechanism
above, but may also be implemented by other means if, for example, the hardware has more direct support for
spinlocks.
HAL_SPINLOCK_TYPE
The type for all spinlock variables.
HAL_SPINLOCK_INIT_CLEAR
A value that may be assigned to a spinlock variable to initialize it to clear.
HAL_SPINLOCK_INIT_SET
A value that may be assigned to a spinlock variable to initialize it to set.
HAL_SPINLOCK_SPIN( lock )
The caller spins in a busy loop waiting for the lock to become clear. It then sets it and continues. This is all
handled atomically, so that there are no race conditions between CPUs.
HAL_SPINLOCK_CLEAR( lock )
The caller clears the lock. One of any waiting spinners will then be able to proceed.
HAL_SPINLOCK_TRY( lock, val )
Attempts to set the lock. The value put in
val
will be
true
if the lock was claimed successfully, and
false
if it was not.
HAL_SPINLOCK_TEST( lock, val )
Tests the current value of the lock. The value put in
val
will be
true
if the lock is claimed and
false
of it is
clear.
Scheduler Lock
The scheduler lock is the main protection for all kernel data structures. By default the kernel implements the
scheduler lock itself using a spinlock. However, if spinlocks cannot be supported by the hardware, or there is a
more efficient implementation available, the HAL may provide macros to implement the scheduler lock.
HAL_SMP_SCHEDLOCK_DATA_TYPE
A data type, possibly a structure, that contains any data items needed by the scheduler lock implementation.
A variable of this type will be instantiated as a static member of the Cyg_Scheduler_SchedLock class and
passed to all the following macros.
HAL_SMP_SCHEDLOCK_INIT( lock, data )
Initialize the scheduler lock. The
lock
argument is the scheduler lock counter and the
data
argument is a
variable of HAL_SMP_SCHEDLOCK_DATA_TYPE type.
195