#include <cafe/mp.h>

inline void MPAcquireSpinLock(MPSpinLock* spinlock);


spinlock Pointer to spinlock.

Return Values



MPAcquireSpinLock busy-waits to acquire a MPSpinLock. MPSpinLock is an inline SMP spinlock implementation, which has a low overhead. This basic spinlock must be used carefully. The intended use is to guard access to shared memory between equal priority threads, each running on a different core.

  1. A deadlock condition may occur if a thread that is holding a spinlock is preempted by a higher priority thread on the same core that wants the same spinlock.
  2. Slower performance than expected may occur if a thread that is holding a spinlock is preempted. Other cores must wait until the holding thread resumes and releases the lock.

Important usage notes while holding a spinlock:

Do not continue to hold a MPSpinLock when a process switch occurs. When performing a process switch, call OSReleaseForeground. A substantial amount of OS work happens during the call, which requires switching threads and coordinating with many of the user-mode drivers on multiple cores.

OSSpinLock (as opposed to MPSpinLock) is designed to handle thread priority inversion issues. Boosting the current thread to highest-priority while holding an OSSpinLock prevents priority-inversion issues. Boosting and deboosting has a time cost and slightly reduces the performance of OSSpinLock.

Do Not Call From

Callbacks Do not call this function from any callback function.

See Also


Revision History

2014/06/19 Edited description.
2013/05/08 Automated cleanup pass.
2010/08/23 Initial version.