summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-12-02 16:40:23 +0100
committerTyge Løvset <[email protected]>2021-12-02 16:40:23 +0100
commit9cd20ebfc4f1e10153ff814085499223265ef902 (patch)
tree13abd2d95ab748f5c06a9c61dc1a8f200a341a2e /include
parentd8588e42dd180b51c6ca8861a426cf4db21c7084 (diff)
downloadSTC-modified-9cd20ebfc4f1e10153ff814085499223265ef902.tar.gz
STC-modified-9cd20ebfc4f1e10153ff814085499223265ef902.zip
shared_ptr atomic count: Using stdatomics.h for other compilers than gcc, clang or msvc.
Diffstat (limited to 'include')
-rw-r--r--include/stc/csptr.h12
1 files changed, 4 insertions, 8 deletions
diff --git a/include/stc/csptr.h b/include/stc/csptr.h
index da52d290..a8496654 100644
--- a/include/stc/csptr.h
+++ b/include/stc/csptr.h
@@ -62,14 +62,10 @@ typedef long atomic_count_t;
#include <intrin.h>
#define c_atomic_inc(v) (void)_InterlockedIncrement(v)
#define c_atomic_dec_and_test(v) !_InterlockedDecrement(v)
-#elif defined(__i386__) || defined(__x86_64__)
- STC_INLINE void c_atomic_inc(atomic_count_t* v)
- { asm volatile("lock; incq %0" :"=m"(*v) :"m"(*v)); }
- STC_INLINE bool c_atomic_dec_and_test(atomic_count_t* v) {
- unsigned char c;
- asm volatile("lock; decq %0; sete %1" :"=m"(*v), "=qm"(c) :"m"(*v) :"memory");
- return !c;
- }
+#else
+ #include <stdatomic.h>
+ #define c_atomic_inc(v) (void)atomic_fetch_add(v, 1)
+ #define c_atomic_dec_and_test(v) (atomic_fetch_sub(v, 1) == 1)
#endif
#define csptr_null {NULL, NULL}