Skip to content
Snippets Groups Projects
Commit 8a4932ff authored by Martin Storsjö's avatar Martin Storsjö
Browse files

Implement atomic_compare_exchange_strong in the atomic compat headers

This fixes building with MSVC (and older GCC versions) after
3e7886db.
parent 3e7886db
No related branches found
No related tags found
1 merge request!1460Implement atomic_compare_exchange_strong in the atomic compat headers
Pipeline #276806 passed with stages
in 6 minutes and 28 seconds
......@@ -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) */
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment