Bug 1187075: Implement cairo atomics for Win32. r=jrmuizel

This commit is contained in:
Bas Schouten 2015-07-24 16:41:02 +00:00
parent 93e401cbb4
commit 066a7c1c18
3 changed files with 30 additions and 1 deletions

View File

@ -45,6 +45,10 @@
#include "config.h"
#endif
#if HAVE_WIN32_ATOMIC_PRIMITIVES
#include <Windows.h>
#endif
/* The autoconf on OpenBSD 4.5 produces the malformed constant name
* SIZEOF_VOID__ rather than SIZEOF_VOID_P. Work around that here. */
#if !defined(SIZEOF_VOID_P) && defined(SIZEOF_VOID__)
@ -143,6 +147,28 @@ _cairo_atomic_ptr_cmpxchg_return_old_impl(void **x, void *oldv, void *newv)
#endif
#if HAVE_WIN32_ATOMIC_PRIMITIVES
#define HAS_ATOMIC_OPS 1
typedef volatile long cairo_atomic_int_t;
# define _cairo_atomic_int_get(x) ((int)*x)
# define _cairo_atomic_ptr_get(x) ((void*)*x)
# 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)
# define _cairo_atomic_int_cmpxchg(x, oldv, newv) (InterlockedCompareExchange(x, newv, oldv) == oldv)
# define _cairo_atomic_int_cmpxchg_return_old(x, oldv, newv) InterlockedCompareExchange(x, newv, oldv)
typedef volatile void* cairo_atomic_intptr_t;
#define _cairo_atomic_ptr_cmpxchg(x, oldv, newv) (InterlockedCompareExchangePointer(x, newv, oldv) == oldv)
#define _cairo_atomic_ptr_cmpxchg_return_old(x, oldv, newv) (InterlockedCompareExchangePointer(x, newv, oldv))
#endif
#if HAVE_INTEL_ATOMIC_PRIMITIVES
#define HAS_ATOMIC_OPS 1

View File

@ -214,6 +214,9 @@
#endif
#ifdef _MSC_VER
#define HAVE_WIN32_ATOMIC_PRIMITIVES 1
#ifndef __cplusplus
#undef inline
#define inline __inline

View File

@ -51,7 +51,7 @@ typedef struct {
#define CAIRO_REFERENCE_COUNT_GET_VALUE(RC) _cairo_atomic_int_get (&(RC)->ref_count)
#define CAIRO_REFERENCE_COUNT_INVALID_VALUE ((cairo_atomic_int_t) -1)
#define CAIRO_REFERENCE_COUNT_INVALID_VALUE (-1)
#define CAIRO_REFERENCE_COUNT_INVALID {CAIRO_REFERENCE_COUNT_INVALID_VALUE}
#define CAIRO_REFERENCE_COUNT_IS_INVALID(RC) (CAIRO_REFERENCE_COUNT_GET_VALUE (RC) == CAIRO_REFERENCE_COUNT_INVALID_VALUE)