mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-03 14:00:18 +01:00
atomic: Add support for WIN32 atomic operations
Windows provides atomic operation APIs so use it
This commit is contained in:
parent
1904d7bf35
commit
cd2b91c62e
1 changed files with 61 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue