Improve atomics

This commit is contained in:
plutoo 2018-03-10 14:41:06 +01:00
parent a102c64341
commit 1d34db8497
2 changed files with 15 additions and 21 deletions

View File

@ -1,6 +1,17 @@
#include "../types.h"
u32 atomicIncrement32(u32* p);
u32 atomicDecrement32(u32* p);
u64 atomicIncrement64(u64* p);
u64 atomicDecrement64(u64* p);
static inline u32 atomicIncrement32(u32* p) {
return __atomic_fetch_add(p, 1, __ATOMIC_SEQ_CST);
}
static inline u32 atomicDecrement32(u32* p) {
return __atomic_sub_fetch(p, 1, __ATOMIC_SEQ_CST);
}
static inline u64 atomicIncrement64(u64* p) {
return __atomic_fetch_add(p, 1, __ATOMIC_SEQ_CST);
}
static inline u64 atomicDecrement64(u64* p) {
return __atomic_sub_fetch(p, 1, __ATOMIC_SEQ_CST);
}

View File

@ -1,17 +0,0 @@
#include "types.h"
u32 atomicIncrement32(u32* p) {
return __sync_fetch_and_add(p, 1);
}
u32 atomicDecrement32(u32* p) {
return __sync_sub_and_fetch(p, 1);
}
u64 atomicIncrement64(u64* p) {
return __sync_fetch_and_add(p, 1);
}
u64 atomicDecrement64(u64* p) {
return __sync_sub_and_fetch(p, 1);
}