arm64: add spinlock implementation
Provide a simple spinlock implentation for arm64. A value of 0 is unlocked and a value of 1 is locked. BUG=chrome-os-partner:31761 BRANCH=None TEST=Built and ran SMP bringup on ryu. Change-Id: I3bf2d80b91112d04442455ff0fa3f16900b7327f Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/216923 Reviewed-by: Furquan Shaikh <furquan@chromium.org>
This commit is contained in:
parent
50079befdc
commit
14dab94610
1 changed files with 24 additions and 1 deletions
|
|
@ -1,6 +1,29 @@
|
|||
#ifndef ARCH_SMP_SPINLOCK_H
|
||||
#define ARCH_SMP_SPINLOCK_H
|
||||
|
||||
#error "spinlocks: implement this for ARM64"
|
||||
#include <arch/barrier.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
volatile uint32_t lock;
|
||||
} spinlock_t;
|
||||
|
||||
#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
|
||||
#define DECLARE_SPIN_LOCK(x) static spinlock_t x = SPIN_LOCK_UNLOCKED;
|
||||
|
||||
static inline void spin_lock(spinlock_t *spin)
|
||||
{
|
||||
while (1) {
|
||||
if (load_acquire_exclusive(&spin->lock) != 0)
|
||||
continue;
|
||||
if (store_release_exclusive(&spin->lock, 1))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void spin_unlock(spinlock_t *spin)
|
||||
{
|
||||
store_release(&spin->lock, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue