spinlock: try and acquire func

This commit is contained in:
Matheus
2022-09-09 18:14:14 -03:00
parent b8c3a7aebc
commit 417c46c040
+6
View File
@@ -1,10 +1,16 @@
#ifndef _SPINLOCK_H_INCLUDE
#define _SPINLOCK_H_INCLUDE
#include <stdbool.h>
static inline void spinlock_acquire(int *lock){
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){
*lock = 0;
}