mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 06:58:22 +00:00
spinlock: try and acquire func
This commit is contained in:
@@ -1,10 +1,16 @@
|
|||||||
#ifndef _SPINLOCK_H_INCLUDE
|
#ifndef _SPINLOCK_H_INCLUDE
|
||||||
#define _SPINLOCK_H_INCLUDE
|
#define _SPINLOCK_H_INCLUDE
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
static inline void spinlock_acquire(int *lock){
|
static inline void spinlock_acquire(int *lock){
|
||||||
while(!__sync_bool_compare_and_swap(lock, 0, 1)) asm("pause");
|
while(!__sync_bool_compare_and_swap(lock, 0, 1)) asm("pause");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool spinlock_trytoacquire(int *lock){
|
||||||
|
return __sync_bool_compare_and_swap(lock, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
static inline void spinlock_release(int *lock){
|
static inline void spinlock_release(int *lock){
|
||||||
*lock = 0;
|
*lock = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user