1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/harfbuzz/src/hb-atomic-private.hh Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,132 @@ 1.4 +/* 1.5 + * Copyright © 2007 Chris Wilson 1.6 + * Copyright © 2009,2010 Red Hat, Inc. 1.7 + * Copyright © 2011,2012 Google, Inc. 1.8 + * 1.9 + * This is part of HarfBuzz, a text shaping library. 1.10 + * 1.11 + * Permission is hereby granted, without written agreement and without 1.12 + * license or royalty fees, to use, copy, modify, and distribute this 1.13 + * software and its documentation for any purpose, provided that the 1.14 + * above copyright notice and the following two paragraphs appear in 1.15 + * all copies of this software. 1.16 + * 1.17 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 1.18 + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 1.19 + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 1.20 + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 1.21 + * DAMAGE. 1.22 + * 1.23 + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 1.24 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 1.25 + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 1.26 + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 1.27 + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 1.28 + * 1.29 + * Contributor(s): 1.30 + * Chris Wilson <chris@chris-wilson.co.uk> 1.31 + * Red Hat Author(s): Behdad Esfahbod 1.32 + * Google Author(s): Behdad Esfahbod 1.33 + */ 1.34 + 1.35 +#ifndef HB_ATOMIC_PRIVATE_HH 1.36 +#define HB_ATOMIC_PRIVATE_HH 1.37 + 1.38 +#include "hb-private.hh" 1.39 + 1.40 + 1.41 +/* atomic_int */ 1.42 + 1.43 +/* We need external help for these */ 1.44 + 1.45 +#if 0 1.46 + 1.47 + 1.48 +#elif !defined(HB_NO_MT) && (defined(_WIN32) || defined(__CYGWIN__)) 1.49 + 1.50 +#define WIN32_LEAN_AND_MEAN 1.51 +#include <windows.h> 1.52 + 1.53 +#if defined(__MINGW32__) && !defined(MemoryBarrier) 1.54 +static inline void _HBMemoryBarrier (void) { 1.55 + long dummy = 0; 1.56 + InterlockedExchange (&dummy, 1); 1.57 +} 1.58 +# define MemoryBarrier _HBMemoryBarrier 1.59 +#endif 1.60 + 1.61 +typedef LONG hb_atomic_int_t; 1.62 +#define hb_atomic_int_add(AI, V) InterlockedExchangeAdd (&(AI), (V)) 1.63 + 1.64 +#define hb_atomic_ptr_get(P) (MemoryBarrier (), (void *) *(P)) 1.65 +#define hb_atomic_ptr_cmpexch(P,O,N) (InterlockedCompareExchangePointer ((void **) (P), (void *) (N), (void *) (O)) == (void *) (O)) 1.66 + 1.67 + 1.68 +#elif !defined(HB_NO_MT) && defined(__APPLE__) 1.69 + 1.70 +#include <libkern/OSAtomic.h> 1.71 +#ifdef __MAC_OS_X_MIN_REQUIRED 1.72 +#include <AvailabilityMacros.h> 1.73 +#elif defined(__IPHONE_OS_MIN_REQUIRED) 1.74 +#include <Availability.h> 1.75 +#endif 1.76 + 1.77 +typedef int32_t hb_atomic_int_t; 1.78 +#define hb_atomic_int_add(AI, V) (OSAtomicAdd32Barrier ((V), &(AI)) - (V)) 1.79 + 1.80 +#define hb_atomic_ptr_get(P) (OSMemoryBarrier (), (void *) *(P)) 1.81 +#if (MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 || __IPHONE_VERSION_MIN_REQUIRED >= 20100) 1.82 +#define hb_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwapPtrBarrier ((void *) (O), (void *) (N), (void **) (P)) 1.83 +#else 1.84 +#if __ppc64__ || __x86_64__ || __arm64__ 1.85 +#define hb_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwap64Barrier ((int64_t) (O), (int64_t) (N), (int64_t*) (P)) 1.86 +#else 1.87 +#define hb_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwap32Barrier ((int32_t) (O), (int32_t) (N), (int32_t*) (P)) 1.88 +#endif 1.89 +#endif 1.90 + 1.91 + 1.92 +#elif !defined(HB_NO_MT) && defined(HAVE_INTEL_ATOMIC_PRIMITIVES) 1.93 + 1.94 +typedef int hb_atomic_int_t; 1.95 +#define hb_atomic_int_add(AI, V) __sync_fetch_and_add (&(AI), (V)) 1.96 + 1.97 +#define hb_atomic_ptr_get(P) (void *) (__sync_synchronize (), *(P)) 1.98 +#define hb_atomic_ptr_cmpexch(P,O,N) __sync_bool_compare_and_swap ((P), (O), (N)) 1.99 + 1.100 + 1.101 +#elif !defined(HB_NO_MT) && defined(HAVE_SOLARIS_ATOMIC_OPS) 1.102 + 1.103 +#include <atomic.h> 1.104 +#include <mbarrier.h> 1.105 + 1.106 +typedef unsigned int hb_atomic_int_t; 1.107 +#define hb_atomic_int_add(AI, V) ( ({__machine_rw_barrier ();}), atomic_add_int_nv (&(AI), (V)) - (V)) 1.108 + 1.109 +#define hb_atomic_ptr_get(P) ( ({__machine_rw_barrier ();}), (void *) *(P)) 1.110 +#define hb_atomic_ptr_cmpexch(P,O,N) ( ({__machine_rw_barrier ();}), atomic_cas_ptr ((void **) (P), (void *) (O), (void *) (N)) == (void *) (O) ? true : false) 1.111 + 1.112 + 1.113 +#elif !defined(HB_NO_MT) 1.114 + 1.115 +#define HB_ATOMIC_INT_NIL 1 /* Warn that fallback implementation is in use. */ 1.116 +typedef volatile int hb_atomic_int_t; 1.117 +#define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V)) 1.118 + 1.119 +#define hb_atomic_ptr_get(P) ((void *) *(P)) 1.120 +#define hb_atomic_ptr_cmpexch(P,O,N) (* (void * volatile *) (P) == (void *) (O) ? (* (void * volatile *) (P) = (void *) (N), true) : false) 1.121 + 1.122 + 1.123 +#else /* HB_NO_MT */ 1.124 + 1.125 +typedef int hb_atomic_int_t; 1.126 +#define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V)) 1.127 + 1.128 +#define hb_atomic_ptr_get(P) ((void *) *(P)) 1.129 +#define hb_atomic_ptr_cmpexch(P,O,N) (* (void **) (P) == (void *) (O) ? (* (void **) (P) = (void *) (N), true) : false) 1.130 + 1.131 +#endif 1.132 + 1.133 +/* TODO Add tracing. */ 1.134 + 1.135 +#endif /* HB_ATOMIC_PRIVATE_HH */