chromium/third_party/fontconfig/src/src/fcatomic.h

/*
 * Mutex operations.  Originally copied from HarfBuzz.
 *
 * Copyright © 2007  Chris Wilson
 * Copyright © 2009,2010  Red Hat, Inc.
 * Copyright © 2011,2012,2013  Google, Inc.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Contributor(s):
 *	Chris Wilson <[email protected]>
 * Red Hat Author(s): Behdad Esfahbod
 * Google Author(s): Behdad Esfahbod
 */

#ifndef _FCATOMIC_H_
#define _FCATOMIC_H_

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif


/* atomic_int */

/* We need external help for these */

#if 0

typedef <type> fc_atomic_int_t;
#define FC_ATOMIC_INT_FORMAT
#define fc_atomic_int_add

#define fc_atomic_ptr_get
#define fc_atomic_ptr_cmpexch


#elif !defined(FC_NO_MT) && defined(HAVE_STDATOMIC_PRIMITIVES)

#include <stdatomic.h>

fc_atomic_int_t;
#define FC_ATOMIC_INT_FORMAT
#define fc_atomic_int_add(AI, V)

#define fc_atomic_ptr_get(P)
static inline FcBool _fc_atomic_ptr_cmpexch(_Atomic(void *)*P, void * O, _Atomic(void *) N) {}
#define fc_atomic_ptr_cmpexch(P,O,N)

/* Casting -1 to _Atomic(int) produces a compiler error with Clang (but not GCC)
 * so we have to override FC_REF_CONSTANT_VALUE for stdatomic.h atomics.
 * See https://bugs.llvm.org/show_bug.cgi?id=40249. */
#define FC_REF_CONSTANT_VALUE

#elif !defined(FC_NO_MT) && defined(_MSC_VER) || defined(__MINGW32__)

#include "fcwindows.h"

typedef LONG fc_atomic_int_t;
#define FC_ATOMIC_INT_FORMAT
#define fc_atomic_int_add

#define fc_atomic_ptr_get
#define fc_atomic_ptr_cmpexch


#elif !defined(FC_NO_MT) && defined(__APPLE__)

#include <libkern/OSAtomic.h>
#include <AvailabilityMacros.h>

typedef int fc_atomic_int_t;
#define FC_ATOMIC_INT_FORMAT
#define fc_atomic_int_add

#if SIZEOF_VOID_P == 8
#define fc_atomic_ptr_get
#elif SIZEOF_VOID_P == 4
#define fc_atomic_ptr_get
#else
#error "SIZEOF_VOID_P not 4 or 8 (assumes CHAR_BIT is 8)"
#endif

#if (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 || __IPHONE_OS_VERSION_MIN_REQUIRED >= 20100)
#define fc_atomic_ptr_cmpexch
#else
#if __LP64__
#define fc_atomic_ptr_cmpexch
#else
#define fc_atomic_ptr_cmpexch
#endif
#endif


#elif !defined(FC_NO_MT) && defined(HAVE_INTEL_ATOMIC_PRIMITIVES)

typedef int fc_atomic_int_t;
#define FC_ATOMIC_INT_FORMAT
#define fc_atomic_int_add

#define fc_atomic_ptr_get
#define fc_atomic_ptr_cmpexch


#elif !defined(FC_NO_MT) && defined(HAVE_SOLARIS_ATOMIC_OPS)

#include <atomic.h>
#include <mbarrier.h>

typedef unsigned int fc_atomic_int_t;
#define FC_ATOMIC_INT_FORMAT
#define fc_atomic_int_add

#define fc_atomic_ptr_get
#define fc_atomic_ptr_cmpexch


#elif !defined(FC_NO_MT)

#define FC_ATOMIC_INT_NIL
typedef volatile int fc_atomic_int_t;
#define FC_ATOMIC_INT_FORMAT
#define fc_atomic_int_add

#define fc_atomic_ptr_get
#define fc_atomic_ptr_cmpexch


#else /* FC_NO_MT */

typedef int fc_atomic_int_t;
#define FC_ATOMIC_INT_FORMAT
#define fc_atomic_int_add

#define fc_atomic_ptr_get
#define fc_atomic_ptr_cmpexch

#endif

/* reference count */
#ifndef FC_REF_CONSTANT_VALUE
#define FC_REF_CONSTANT_VALUE
#endif
#define FC_REF_CONSTANT
FcRef;
static inline void   FcRefInit     (FcRef *r, int v) {}
static inline int    FcRefInc      (FcRef *r) {}
static inline int    FcRefDec      (FcRef *r) {}
static inline int    FcRefAdd      (FcRef *r, int v) {}
static inline void   FcRefSetConst (FcRef *r) {}
static inline FcBool FcRefIsConst  (const FcRef *r) {}

#endif /* _FCATOMIC_H_ */