mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 20:58:22 +00:00
spinlock: introduce helpers that clear & restore interrupts
These are just wrappers around acquire/release that clear and restore interrupts respectively.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define _SPINLOCK_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <kernel/interrupt.h>
|
||||
|
||||
typedef int spinlock_t;
|
||||
|
||||
@@ -11,6 +12,12 @@ static inline void spinlock_acquire(spinlock_t *lock){
|
||||
while(!__sync_bool_compare_and_swap(lock, 0, 1)) asm("pause");
|
||||
}
|
||||
|
||||
static inline bool spinlock_acquireirqclear(spinlock_t *lock){
|
||||
bool ret = interrupt_set(false);
|
||||
spinlock_acquire(lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline bool spinlock_try(spinlock_t *lock){
|
||||
return __sync_bool_compare_and_swap(lock, 0, 1);
|
||||
}
|
||||
@@ -19,4 +26,9 @@ static inline void spinlock_release(spinlock_t *lock){
|
||||
*lock = 0;
|
||||
}
|
||||
|
||||
static inline void spinlock_releaseirqrestore(spinlock_t *lock, bool irqstate){
|
||||
spinlock_release(lock);
|
||||
interrupt_set(irqstate);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user