21 lines
416 B
C
21 lines
416 B
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
#include <kernel/common.h>
|
|
#include <kernel/spinlock.h>
|
|
|
|
int atomic_cmpxchg(spinlock_t *lock, int a, int b);
|
|
|
|
static uint64_t spinlock_attempt_acquire(spinlock_t *lock)
|
|
{
|
|
return atomic_cmpxchg(lock, 0, 1);
|
|
}
|
|
|
|
void spinlock_acquire(spinlock_t *lock)
|
|
{
|
|
while (spinlock_attempt_acquire(lock))
|
|
;
|
|
}
|
|
|
|
void spinlock_release(spinlock_t *lock)
|
|
{
|
|
atomic_cmpxchg(lock, 1, 0);
|
|
}
|