From 7a6c0f23fabcf7bf94959de6535d754fdf51dbb2 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 13 Aug 2023 02:01:02 -0400 Subject: [PATCH] fix: musl compilation --- lib/src/atomic.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/src/atomic.h b/lib/src/atomic.h index e8a2060a..d91c2c0b 100644 --- a/lib/src/atomic.h +++ b/lib/src/atomic.h @@ -1,6 +1,7 @@ #ifndef TREE_SITTER_ATOMIC_H_ #define TREE_SITTER_ATOMIC_H_ +#include #include #ifdef __TINYC__ @@ -46,11 +47,19 @@ static inline size_t atomic_load(const volatile size_t *p) { } static inline uint32_t atomic_inc(volatile uint32_t *p) { - return __sync_add_and_fetch(p, 1U); + #ifdef __ATOMIC_RELAXED + return __atomic_add_fetch(p, 1U, __ATOMIC_RELAXED); + #else + return __sync_add_and_fetch(p, 1U); + #endif } static inline uint32_t atomic_dec(volatile uint32_t *p) { - return __sync_sub_and_fetch(p, 1U); + #ifdef __ATOMIC_RELAXED + return __atomic_sub_fetch(p, 1U, __ATOMIC_RELAXED); + #else + return __sync_sub_and_fetch(p, 1U); + #endif } #endif