Switch to nanoprintf + good spinlock (rflags) = no more FLANTERM ISSUES???
This commit is contained in:
29
src/sched/spinlock.c
Normal file
29
src/sched/spinlock.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @brief Spinlock implementation
|
||||
* @license GPL-3.0-only
|
||||
*/
|
||||
|
||||
#include <stdatomic.h>
|
||||
#include <stdbool.h>
|
||||
#include "kernel.h"
|
||||
#include "spinlock.h"
|
||||
|
||||
void spinlock_acquire(struct spinlock_t* lock)
|
||||
{
|
||||
uint64_t rflags;
|
||||
asm volatile("pushfq ; pop %0 ; cli" : "=rm"(rflags) : : "memory");
|
||||
|
||||
while (__atomic_test_and_set(&lock->locked, __ATOMIC_ACQUIRE)) {
|
||||
__builtin_ia32_pause();
|
||||
}
|
||||
|
||||
lock->rflags = rflags;
|
||||
}
|
||||
|
||||
void spinlock_release(struct spinlock_t* lock)
|
||||
{
|
||||
uint64_t rflags = lock->rflags;
|
||||
__atomic_clear(&lock->locked, __ATOMIC_RELEASE);
|
||||
asm volatile("push %0 ; popfq" : : "rm"(rflags) : "memory");
|
||||
}
|
||||
Reference in New Issue
Block a user