Luna/kernel/src/thread/Spinlock.asm

26 lines
424 B
NASM
Raw Normal View History

2022-09-18 18:15:19 +00:00
global spinlock_lock_acquire
spinlock_lock_acquire:
lock bts qword [rdi], 0
jc .spin
ret
.spin:
pause
test qword [rdi], 1
jnz .spin
jmp spinlock_lock_acquire
global spinlock_lock_release
spinlock_lock_release:
mov qword [rdi], 0
ret
global spinlock_lock_is_locked
spinlock_lock_is_locked:
cmp qword [rdi], 0
je .free
.locked:
mov rax, 1
ret
.free:
mov rax, 0
ret