lock: merge spinlock and mtx locks into one
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
3e5abada9b
commit
2076f1dae1
32 changed files with 158 additions and 169 deletions
|
|
@ -1,10 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _MTX_H_
|
||||
#define _MTX_H_
|
||||
|
||||
#include <kernel/spinlock.h>
|
||||
|
||||
void mtx_lock(mtx_t *l);
|
||||
void mtx_unlock(mtx_t *l);
|
||||
|
||||
#endif /* _MTX_H_ */
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _SPINLOCK_H_
|
||||
#define _SPINLOCK_H_
|
||||
|
||||
#include <kernel/types.h>
|
||||
#include <kernel/common.h>
|
||||
|
||||
#define CLEANUP_SLOCK CLEANUP(cleanup_spinlock)
|
||||
|
||||
typedef u32 spinlock_t;
|
||||
typedef spinlock_t mtx_t;
|
||||
|
||||
void spinlock_acquire(spinlock_t *lock);
|
||||
void spinlock_release(spinlock_t *lock);
|
||||
void cleanup_spinlock(spinlock_t **lock_ptr);
|
||||
|
||||
#endif /* _SPINLOCK_H_ */
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
obj-y += atomic.o
|
||||
obj-y += spinlock.o
|
||||
obj-y += lock.o
|
||||
obj-y += thread.o
|
||||
obj-y += time.o
|
||||
obj-y += tsc.o
|
||||
|
|
|
|||
|
|
@ -1,39 +1,39 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/spinlock.h>
|
||||
#include <kernel/lock.h>
|
||||
#include <kernel/atomic.h>
|
||||
#include <kernel/thread.h>
|
||||
#include <arch/proc.h>
|
||||
|
||||
static uint64_t spinlock_attempt_acquire(spinlock_t *lock)
|
||||
static uint64_t spinlock_attempt_acquire(lock_t *lock)
|
||||
{
|
||||
return atomic_cmpxchg(lock, 0, 1);
|
||||
}
|
||||
|
||||
void spinlock_acquire(spinlock_t *lock)
|
||||
void spin_lock(lock_t *lock)
|
||||
{
|
||||
while (spinlock_attempt_acquire(lock))
|
||||
;
|
||||
}
|
||||
|
||||
void spinlock_release(spinlock_t *lock)
|
||||
void spin_unlock(lock_t *lock)
|
||||
{
|
||||
atomic_cmpxchg(lock, 1, 0);
|
||||
}
|
||||
|
||||
void cleanup_spinlock(spinlock_t **lock_ptr)
|
||||
void cleanup_spinlock(lock_t **lock_ptr)
|
||||
{
|
||||
if (lock_ptr && *lock_ptr)
|
||||
spinlock_release(*lock_ptr);
|
||||
spin_unlock(*lock_ptr);
|
||||
}
|
||||
|
||||
void mtx_lock(mtx_t *l)
|
||||
void mtx_lock(lock_t *l)
|
||||
{
|
||||
while (spinlock_attempt_acquire(l))
|
||||
reschedule(THREAD_STATE_WAITING);
|
||||
}
|
||||
|
||||
void mtx_unlock(mtx_t *l)
|
||||
void mtx_unlock(lock_t *l)
|
||||
{
|
||||
spinlock_release(l);
|
||||
spin_unlock(l);
|
||||
}
|
||||
Loading…
Reference in a new issue