22 lines
463 B
C
22 lines
463 B
C
#ifndef SPINLOCK_SPINLOCK_H_
|
|
#define SPINLOCK_SPINLOCK_H_
|
|
|
|
#include <stdatomic.h>
|
|
#include <stdint.h>
|
|
#include "hal/hal.h"
|
|
|
|
typedef struct { atomic_bool lock; } SpinLock;
|
|
|
|
// Spin more efficiently - cpu dependant
|
|
#if defined(__x86_64__)
|
|
# define SPINLOCK_HINT() asm volatile("pause")
|
|
#else
|
|
# define SPINLOCK_HINT()
|
|
#endif
|
|
|
|
void spinlock_init(SpinLock *sl);
|
|
void spinlock_acquire(SpinLock *sl);
|
|
void spinlock_release(SpinLock *sl);
|
|
|
|
#endif // SPINLOCK_SPINLOCK_H_
|