summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-11-26 11:57:10 +0100
committerTyge Løvset <[email protected]>2021-11-26 11:57:10 +0100
commit30f6b34e1d1451f08a652b940d3ff3e1b9adc1e4 (patch)
tree93569d3acddd3b7fd8db1c3cbd37732b2c0182f9 /include
parentcde7c39de3492f8b701038af6563a6c4e01ff558 (diff)
downloadSTC-modified-30f6b34e1d1451f08a652b940d3ff3e1b9adc1e4.tar.gz
STC-modified-30f6b34e1d1451f08a652b940d3ff3e1b9adc1e4.zip
Fixed atomic_decrement final.
Diffstat (limited to 'include')
-rw-r--r--include/stc/csptr.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/include/stc/csptr.h b/include/stc/csptr.h
index b702f461..10063bcd 100644
--- a/include/stc/csptr.h
+++ b/include/stc/csptr.h
@@ -57,16 +57,19 @@ int main() {
typedef long atomic_count_t;
#if defined(__GNUC__) || defined(__clang__)
#define c_atomic_increment(v) (void)__atomic_add_fetch(v, 1, __ATOMIC_SEQ_CST)
- #define c_atomic_decrement(v) __atomic_sub_fetch(v, 1, __ATOMIC_SEQ_CST)
+ #define c_atomic_decrement(v) (bool)__atomic_sub_fetch(v, 1, __ATOMIC_SEQ_CST)
#elif defined(_MSC_VER)
#include <intrin.h>
#define c_atomic_increment(v) (void)_InterlockedIncrement(v)
- #define c_atomic_decrement(v) _InterlockedDecrement(v)
+ #define c_atomic_decrement(v) (bool)_InterlockedDecrement(v)
#elif defined(__i386__) || defined(__x86_64__)
STC_INLINE void c_atomic_increment(atomic_count_t* v)
- { __asm__ __volatile__("lock; incq %0" :"=m"(*v) :"m"(*v)); }
- STC_INLINE atomic_count_t c_atomic_decrement(atomic_count_t* v)
- { __asm__ __volatile__("lock; decq %0" :"=m"(*v) :"m"(*v)); return *v; }
+ { asm volatile("lock; incq %0" :"=m"(*v) :"m"(*v)); }
+ STC_INLINE bool c_atomic_decrement(atomic_count_t* v) {
+ unsigned char c;
+ asm volatile("lock; decq %0; sete %1" :"=m"(*v), "=qm"(c) :"m"(*v) :"memory");
+ return !c;
+ }
#endif
#define csptr_null {NULL, NULL}