lock: merge spinlock and mtx locks into one

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-08-13 14:19:10 -04:00
commit 2076f1dae1
Signed by: michaelsshaw
GPG key ID: 5A5E0FB20708A9E7
32 changed files with 158 additions and 169 deletions

View file

@ -1,39 +0,0 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <kernel/common.h>
#include <kernel/spinlock.h>
#include <kernel/atomic.h>
#include <kernel/thread.h>
#include <arch/proc.h>
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);
}
void cleanup_spinlock(spinlock_t **lock_ptr)
{
if (lock_ptr && *lock_ptr)
spinlock_release(*lock_ptr);
}
void mtx_lock(mtx_t *l)
{
while (spinlock_attempt_acquire(l))
reschedule(THREAD_STATE_WAITING);
}
void mtx_unlock(mtx_t *l)
{
spinlock_release(l);
}