Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/videolan/dav1d.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2022-10-26 10:00:01 +0300
committerMartin Storsjö <martin@martin.st>2022-10-26 16:14:52 +0300
commit8a4932ff035e2fd2b139caa73f6593c2a4754f67 (patch)
tree10059c2c8dc866c3ce977a1adfb39370cfb639d7
parent3e7886db54d0cb3ce32909c71ad2a8c9d9eab223 (diff)
Implement atomic_compare_exchange_strong in the atomic compat headers
This fixes building with MSVC (and older GCC versions) after 3e7886db54d0cb3ce32909c71ad2a8c9d9eab223.
-rw-r--r--include/compat/gcc/stdatomic.h1
-rw-r--r--include/compat/msvc/stdatomic.h9
2 files changed, 10 insertions, 0 deletions
diff --git a/include/compat/gcc/stdatomic.h b/include/compat/gcc/stdatomic.h
index da38c52..29f9063 100644
--- a/include/compat/gcc/stdatomic.h
+++ b/include/compat/gcc/stdatomic.h
@@ -44,6 +44,7 @@ typedef unsigned int atomic_uint;
#define atomic_fetch_sub(p_a, dec) __atomic_fetch_sub(p_a, dec, __ATOMIC_SEQ_CST)
#define atomic_exchange(p_a, v) __atomic_exchange_n(p_a, v, __ATOMIC_SEQ_CST)
#define atomic_fetch_or(p_a, v) __atomic_fetch_or(p_a, v, __ATOMIC_SEQ_CST)
+#define atomic_compare_exchange_strong(p_a, expected, desired) __atomic_compare_exchange_n(p_a, expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
#endif /* !defined(__cplusplus) */
diff --git a/include/compat/msvc/stdatomic.h b/include/compat/msvc/stdatomic.h
index cd04a38..618f0ee 100644
--- a/include/compat/msvc/stdatomic.h
+++ b/include/compat/msvc/stdatomic.h
@@ -55,6 +55,15 @@ typedef enum {
#define atomic_exchange(p_a, v) InterlockedExchange(p_a, v)
#define atomic_load_explicit(p_a, mo) atomic_load(p_a)
+static inline int atomic_compare_exchange_strong_int(LONG *obj, LONG *expected,
+ LONG desired)
+{
+ LONG orig = *expected;
+ *expected = InterlockedCompareExchange(obj, desired, orig);
+ return *expected == orig;
+}
+#define atomic_compare_exchange_strong(p_a, expected, desired) atomic_compare_exchange_strong_int((LONG *)p_a, (LONG *)expected, (LONG)desired)
+
/*
* TODO use a special call to increment/decrement
* using InterlockedIncrement/InterlockedDecrement