Userspace dlmalloc port, supporting syscalls mman_map()/mman_unmap()
This commit is contained in:
18
ulib/sync/spinlock.c
Normal file
18
ulib/sync/spinlock.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include <stdatomic.h>
|
||||
#include <sync/spinlock.h>
|
||||
|
||||
#define HINT() asm volatile("pause");
|
||||
|
||||
void spinlock_init(SpinLock *sl) {
|
||||
atomic_store(&sl->lock, false);
|
||||
}
|
||||
|
||||
void spinlock_acquire(SpinLock *sl) {
|
||||
while (atomic_test_and_set_explicit(&sl->lock, memory_order_release)) {
|
||||
HINT();
|
||||
}
|
||||
}
|
||||
|
||||
void spinlock_release(SpinLock *sl) {
|
||||
atomic_clear_flag_explicit(&sl->lock, memory_order_release);
|
||||
}
|
Reference in New Issue
Block a user