Merge branch 'win32-atomic' into 'master'

atomic: Add support for WIN32 atomic operations

See merge request cairo/cairo!151
This commit is contained in:
Tim-Philipp Müller 2021-04-12 08:30:57 +00:00
commit c287fb3a1f

View file

@ -279,6 +279,67 @@ typedef int64_t cairo_atomic_intptr_t;
#endif
#if !defined(HAS_ATOMIC_OPS) && defined(_WIN32)
#include <windows.h>
#define HAS_ATOMIC_OPS 1
typedef int32_t cairo_atomic_int_t;
#if SIZEOF_VOID_P==SIZEOF_INT
typedef unsigned int cairo_atomic_intptr_t;
#elif SIZEOF_VOID_P==SIZEOF_LONG
typedef unsigned long cairo_atomic_intptr_t;
#elif SIZEOF_VOID_P==SIZEOF_LONG_LONG
typedef unsigned long long cairo_atomic_intptr_t;
#else
#error No matching integer pointer type
#endif
static cairo_always_inline cairo_atomic_int_t
_cairo_atomic_int_get (cairo_atomic_int_t *x)
{
MemoryBarrier ();
return *x;
}
# define _cairo_atomic_int_get_relaxed(x) *(x)
# define _cairo_atomic_int_set_relaxed(x, val) *(x) = (val)
# define _cairo_atomic_int_inc(x) ((void) InterlockedIncrement (x))
# define _cairo_atomic_int_dec(x) ((void) InterlockedDecrement (x))
# define _cairo_atomic_int_dec_and_test(x) (InterlockedDecrement (x) == 0)
static cairo_always_inline cairo_bool_t
_cairo_atomic_int_cmpxchg (cairo_atomic_int_t *x,
cairo_atomic_int_t oldv,
cairo_atomic_int_t newv)
{
return InterlockedCompareExchange (x, newv, oldv) == oldv;
}
static cairo_always_inline void *
_cairo_atomic_ptr_get (void **x)
{
MemoryBarrier ();
return *x;
}
static cairo_always_inline cairo_bool_t
_cairo_atomic_ptr_cmpxchg (void **x, void *oldv, void *newv)
{
return InterlockedCompareExchangePointer (x, newv, oldv) == oldv;
}
static cairo_always_inline void *
_cairo_atomic_ptr_cmpxchg_return_old (void **x, void *oldv, void *newv)
{
return InterlockedCompareExchangePointer (x, newv, oldv);
}
#endif /* !defined(HAS_ATOMIC_OPS) && defined(_WIN32) */
#ifndef HAS_ATOMIC_OPS
#if SIZEOF_VOID_P==SIZEOF_INT