coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
spinlock.h File Reference
#include <thread.h>
Include dependency graph for spinlock.h:

Go to the source code of this file.

Data Structures

struct  spinlock_t
 

Macros

#define SPIN_LOCK_UNLOCKED   { 1 }
 
#define DECLARE_SPIN_LOCK(x)    static spinlock_t x = SPIN_LOCK_UNLOCKED;
 
#define barrier()   __asm__ __volatile__("" : : : "memory")
 
#define spin_is_locked(x)   (*(volatile int *)(&(x)->lock) <= 0)
 
#define spin_unlock_wait(x)   do { barrier(); } while (spin_is_locked(x))
 
#define spin_lock_string
 
#define spin_unlock_string    "movl $1,%0"
 

Functions

static __always_inline void spin_lock (spinlock_t *lock)
 
static __always_inline void spin_unlock (spinlock_t *lock)
 

Macro Definition Documentation

◆ barrier

#define barrier (   void)    __asm__ __volatile__("" : : : "memory")

Definition at line 27 of file spinlock.h.

◆ DECLARE_SPIN_LOCK

#define DECLARE_SPIN_LOCK (   x)     static spinlock_t x = SPIN_LOCK_UNLOCKED;

Definition at line 18 of file spinlock.h.

◆ spin_is_locked

#define spin_is_locked (   x)    (*(volatile int *)(&(x)->lock) <= 0)

Definition at line 28 of file spinlock.h.

◆ spin_lock_string

#define spin_lock_string
Value:
"\n1:\t" \
"lock ; decl %0\n\t" \
"js 2f\n" \
".section .text.lock,\"ax\"\n" \
"2:\t" \
"cmpl $0,%0\n\t" \
"rep;nop\n\t" \
"jle 2b\n\t" \
"jmp 1b\n" \
".previous"

Definition at line 32 of file spinlock.h.

◆ SPIN_LOCK_UNLOCKED

#define SPIN_LOCK_UNLOCKED   { 1 }

Definition at line 16 of file spinlock.h.

◆ spin_unlock_string

#define spin_unlock_string    "movl $1,%0"

Definition at line 47 of file spinlock.h.

◆ spin_unlock_wait

#define spin_unlock_wait (   x)    do { barrier(); } while (spin_is_locked(x))

Definition at line 29 of file spinlock.h.

Function Documentation

◆ spin_lock()

static __always_inline void spin_lock ( spinlock_t lock)
static

Definition at line 50 of file spinlock.h.

References lock(), spin_lock_string, and thread_coop_disable().

Here is the call graph for this function:

◆ spin_unlock()

static __always_inline void spin_unlock ( spinlock_t lock)
static

Definition at line 61 of file spinlock.h.

References lock(), spin_unlock_string, and thread_coop_enable().

Here is the call graph for this function: