Spin locks are a means of providing mutual exclusion between (primarily) different CPU cores in an SMP environment.  In some cases they may also provide mutual exclusion between interrupt service routines and other threads or processes which are operating 'inside scheduler space'.  As you point out, they do not sleep. They simply spin in place until either another CPU core releases the lock or until the spinning thread is preempted by another thread (for example an ISR) which currently holds the lock on the same core.

The PREEMPT_RT_FULL kernel changes most spin locks into rt_mutexes, which wait for shared resources on a priority basis and provide priority inheritance.  However, rt_mutexes put the waiting thread or process to sleep until it obtains the requested lock.  Threads running in contexts outside the scheduler (in interrupt context) or running inside 'critical sections' during which preemption is disabled are prohibited from sleeping since the scheduler cannot awaken them.  For this reason, in the PREEMPT_RT_FULL kernel there is a distinction made between 'spin locks' and 'raw spin locks'.  The former are transformed into priority-based sleeping locks, while the 'raw spin locks'  remain unchanged and retain their traditional non-sleeping wait behavior.  This allows raw spin locks to be used inside critical sections and outside of 'scheduler space'.

Gary Robertson
Real-time Engineer,, Linaro



On Sun, Oct 27, 2013 at 9:18 AM, Ryan <ryanphilips19@googlemail.com> wrote:
Hi,

What is a raw spin lock made by the call: DEFINE_RAW_SPINLOCK

When someone locks - it just keeps looping until it 0 & then set it to 1
and when someone unlocks it makes it 0.

is this how this works?

/Ryan

_______________________________________________
linaro-dev mailing list
linaro-dev@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-dev