Mailbox support for texture layers.
[chromium-blink-merge.git] / third_party / harfbuzz-ng / src / hb-atomic-private.hh
blob5861a7124b3ddca64453796726ca72b8d635cf48
1 /*
2 * Copyright © 2007 Chris Wilson
3 * Copyright © 2009,2010 Red Hat, Inc.
4 * Copyright © 2011,2012 Google, Inc.
6 * This is part of HarfBuzz, a text shaping library.
8 * Permission is hereby granted, without written agreement and without
9 * license or royalty fees, to use, copy, modify, and distribute this
10 * software and its documentation for any purpose, provided that the
11 * above copyright notice and the following two paragraphs appear in
12 * all copies of this software.
14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
15 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
17 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * DAMAGE.
20 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
21 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
23 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
24 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
26 * Contributor(s):
27 * Chris Wilson <chris@chris-wilson.co.uk>
28 * Red Hat Author(s): Behdad Esfahbod
29 * Google Author(s): Behdad Esfahbod
32 #ifndef HB_ATOMIC_PRIVATE_HH
33 #define HB_ATOMIC_PRIVATE_HH
35 #include "hb-private.hh"
38 /* atomic_int */
40 /* We need external help for these */
42 #if 0
45 #elif !defined(HB_NO_MT) && defined(_MSC_VER) || defined(__MINGW32__)
47 #define WIN32_LEAN_AND_MEAN
48 #include <windows.h>
50 /* mingw32 does not have MemoryBarrier.
51 * MemoryBarrier may be defined as a macro or a function.
52 * Just make a failsafe version for ourselves. */
53 #ifdef MemoryBarrier
54 #define HBMemoryBarrier MemoryBarrier
55 #else
56 static inline void HBMemoryBarrier (void) {
57 long dummy = 0;
58 InterlockedExchange (&dummy, 1);
60 #endif
62 typedef long hb_atomic_int_t;
63 #define hb_atomic_int_add(AI, V) InterlockedExchangeAdd (&(AI), (V))
65 #define hb_atomic_ptr_get(P) (HBMemoryBarrier (), (void *) *(P))
66 #define hb_atomic_ptr_cmpexch(P,O,N) (InterlockedCompareExchangePointer ((void **) (P), (void *) (N), (void *) (O)) == (void *) (O))
69 #elif !defined(HB_NO_MT) && defined(__APPLE__)
71 #include <libkern/OSAtomic.h>
73 typedef int32_t hb_atomic_int_t;
74 #define hb_atomic_int_add(AI, V) (OSAtomicAdd32Barrier ((V), &(AI)) - (V))
76 #define hb_atomic_ptr_get(P) (OSMemoryBarrier (), (void *) *(P))
77 #define hb_atomic_ptr_cmpexch(P,O,N) OSAtomicCompareAndSwapPtrBarrier ((void *) (O), (void *) (N), (void **) (P))
80 #elif !defined(HB_NO_MT) && defined(HAVE_INTEL_ATOMIC_PRIMITIVES)
82 typedef int hb_atomic_int_t;
83 #define hb_atomic_int_add(AI, V) __sync_fetch_and_add (&(AI), (V))
85 #define hb_atomic_ptr_get(P) (void *) (__sync_synchronize (), *(P))
86 #define hb_atomic_ptr_cmpexch(P,O,N) __sync_bool_compare_and_swap ((P), (O), (N))
89 #elif !defined(HB_NO_MT)
91 #define HB_ATOMIC_INT_NIL 1 /* Warn that fallback implementation is in use. */
92 typedef volatile int hb_atomic_int_t;
93 #define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V))
95 #define hb_atomic_ptr_get(P) ((void *) *(P))
96 #define hb_atomic_ptr_cmpexch(P,O,N) (* (void * volatile *) (P) == (void *) (O) ? (* (void * volatile *) (P) = (void *) (N), true) : false)
99 #else /* HB_NO_MT */
101 typedef int hb_atomic_int_t;
102 #define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V))
104 #define hb_atomic_ptr_get(P) ((void *) *(P))
105 #define hb_atomic_ptr_cmpexch(P,O,N) (* (void **) (P) == (void *) (O) ? (* (void **) (P) = (void *) (N), true) : false)
107 #endif
109 /* TODO Add tracing. */
111 #endif /* HB_ATOMIC_PRIVATE_HH */