coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
spinlock.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef ARCH_SMP_SPINLOCK_H
4 #define ARCH_SMP_SPINLOCK_H
5 
6 #include <arch/barrier.h>
7 #include <arch/smp/atomic.h>
8 
9 typedef struct {
11 } spinlock_t;
12 
13 static inline void spinlock_lock(spinlock_t *lock)
14 {
15  while (atomic_swap(&lock->lock, -1))
16  ;
17  barrier();
18 }
19 
20 static inline void spinlock_unlock(spinlock_t *lock)
21 {
22  barrier();
23  atomic_set(&lock->lock, 0);
24 }
25 
26 #endif // ARCH_SMP_SPINLOCK_H
#define atomic_set(v, val)
Definition: atomic.h:13
static int atomic_swap(atomic_t *v, int swp)
Definition: atomic.h:33
static void spinlock_unlock(spinlock_t *lock)
Definition: spinlock.h:20
static void spinlock_lock(spinlock_t *lock)
Definition: spinlock.h:13
atomic_t barrier
Definition: mp_init.c:0
static void lock(void *unused)
Definition: lockdown.c:58
Definition: atomic.h:8
atomic_t lock
Definition: spinlock.h:10