GDT finally works
This commit is contained in:
31
kernel/spinlock.h
Normal file
31
kernel/spinlock.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef SPINLOCK_SPINLOCK_H_
|
||||
#define SPINLOCK_SPINLOCK_H_
|
||||
|
||||
#include <stdatomic.h>
|
||||
#include "hal/hal.h"
|
||||
|
||||
typedef atomic_bool SpinLock;
|
||||
|
||||
// Spin more efficiently - cpu dependant
|
||||
#if defined(__x86_64__)
|
||||
# define SPINLOCK_HINT() asm volatile("pause")
|
||||
#else
|
||||
# define SPINLOCK_HINT()
|
||||
#endif
|
||||
|
||||
#define SPINLOCK_ACQUIRE(sl) \
|
||||
do { \
|
||||
bool __unlocked = false; \
|
||||
while (!atomic_compare_exchange_weak((sl), &__unlocked, true)) { \
|
||||
SPINLOCK_HINT(); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define SPINLOCK_RELEASE(sl) \
|
||||
do { \
|
||||
atomic_store((sl), false); \
|
||||
} while(0)
|
||||
|
||||
#define SPINLOCK_INIT() false
|
||||
|
||||
#endif // SPINLOCK_SPINLOCK_H_
|
Reference in New Issue
Block a user