blob: 60b319afa534f6d849fa4565badf778ee0168ab1 [file] [log] [blame]
Behdad Esfahbodec3ba4b2012-05-17 20:30:46 -04001/*
2 * Copyright © 2007 Chris Wilson
3 * Copyright © 2009,2010 Red Hat, Inc.
Behdad Esfahbod34961e32012-05-17 20:50:38 -04004 * Copyright © 2011,2012 Google, Inc.
Behdad Esfahbodec3ba4b2012-05-17 20:30:46 -04005 *
6 * This is part of HarfBuzz, a text shaping library.
7 *
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.
13 *
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.
19 *
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.
25 *
26 * Contributor(s):
27 * Chris Wilson <chris@chris-wilson.co.uk>
28 * Red Hat Author(s): Behdad Esfahbod
29 * Google Author(s): Behdad Esfahbod
30 */
31
32#ifndef HB_ATOMIC_PRIVATE_HH
33#define HB_ATOMIC_PRIVATE_HH
34
35#include "hb-private.hh"
36
37
38/* atomic_int */
39
40/* We need external help for these */
41
Behdad Esfahbod34961e32012-05-17 20:50:38 -040042
43#if !defined(HB_NO_MT) && defined(_MSC_VER) && _MSC_VER >= 1600
44
45#include <intrin.h>
46typedef long hb_atomic_int_t;
Behdad Esfahbod22afd662012-05-17 21:23:49 -040047#define hb_atomic_int_add(AI, V) _InterlockedExchangeAdd (&(AI), (V))
48#define hb_atomic_int_set(AI, V) _InterlockedExchange (&(AI), (V))
Behdad Esfahbod34961e32012-05-17 20:50:38 -040049#define hb_atomic_int_get(AI) (_ReadBarrier (), (AI))
50
51
52#elif !defined(HB_NO_MT) && defined(__APPLE__)
53
54#include <libkern/OSAtomic.h>
55typedef int32_t hb_atomic_int_t;
56#define hb_atomic_int_add(AI, V) (OSAtomicAdd32Barrier((V), &(AI)), (AI) - (V))
57#define hb_atomic_int_get(AI) OSAtomicAdd32Barrier(0, &(AI))
58
59
60#elif !defined(HB_NO_MT) && defined(HAVE_GLIB)
Behdad Esfahbodec3ba4b2012-05-17 20:30:46 -040061
62#include <glib.h>
63typedef volatile int hb_atomic_int_t;
64#if GLIB_CHECK_VERSION(2,29,5)
Behdad Esfahbod22afd662012-05-17 21:23:49 -040065#define hb_atomic_int_add(AI, V) g_atomic_int_add (&(AI), (V))
Behdad Esfahbodec3ba4b2012-05-17 20:30:46 -040066#else
Behdad Esfahbod22afd662012-05-17 21:23:49 -040067#define hb_atomic_int_add(AI, V) g_atomic_int_exchange_and_add (&(AI), (V))
Behdad Esfahbodec3ba4b2012-05-17 20:30:46 -040068#endif
Behdad Esfahbod22afd662012-05-17 21:23:49 -040069#define hb_atomic_int_set(AI, V) g_atomic_int_set (&(AI), (V))
Behdad Esfahbodec3ba4b2012-05-17 20:30:46 -040070#define hb_atomic_int_get(AI) g_atomic_int_get (&(AI))
71
72
Behdad Esfahbodec3ba4b2012-05-17 20:30:46 -040073#else
74
75#define HB_ATOMIC_INT_NIL 1
76typedef volatile int hb_atomic_int_t;
77#define hb_atomic_int_add(AI, V) ((AI) += (V), (AI) - (V))
Behdad Esfahbod22afd662012-05-17 21:23:49 -040078#define hb_atomic_int_set(AI) ((void) ((AI) = (V)))
Behdad Esfahbodec3ba4b2012-05-17 20:30:46 -040079#define hb_atomic_int_get(AI) (AI)
80
81#endif
82
83
84#endif /* HB_ATOMIC_PRIVATE_HH */