OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2007 Chris Wilson | 2 * Copyright © 2007 Chris Wilson |
3 * Copyright © 2009,2010 Red Hat, Inc. | 3 * Copyright © 2009,2010 Red Hat, Inc. |
4 * Copyright © 2011,2012 Google, Inc. | 4 * Copyright © 2011,2012 Google, Inc. |
5 * | 5 * |
6 * This is part of HarfBuzz, a text shaping library. | 6 * This is part of HarfBuzz, a text shaping library. |
7 * | 7 * |
8 * Permission is hereby granted, without written agreement and without | 8 * Permission is hereby granted, without written agreement and without |
9 * license or royalty fees, to use, copy, modify, and distribute this | 9 * license or royalty fees, to use, copy, modify, and distribute this |
10 * software and its documentation for any purpose, provided that the | 10 * software and its documentation for any purpose, provided that the |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "hb-private.hh" | 35 #include "hb-private.hh" |
36 | 36 |
37 | 37 |
38 /* atomic_int */ | 38 /* atomic_int */ |
39 | 39 |
40 /* We need external help for these */ | 40 /* We need external help for these */ |
41 | 41 |
42 #if 0 | 42 #if 0 |
43 | 43 |
44 | 44 |
45 #elif !defined(HB_NO_MT) && defined(_MSC_VER) || defined(__MINGW32__) | 45 #elif !defined(HB_NO_MT) && (defined(_WIN32) || defined(__CYGWIN__)) |
46 | 46 |
47 #define WIN32_LEAN_AND_MEAN | 47 #define WIN32_LEAN_AND_MEAN |
48 #include <windows.h> | 48 #include <windows.h> |
49 | 49 |
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); | |
59 } | |
60 #endif | |
61 | |
62 typedef LONG hb_atomic_int_t; | 50 typedef LONG hb_atomic_int_t; |
63 #define hb_atomic_int_add(AI, V) InterlockedExchangeAdd (&(AI), (V)) | 51 #define hb_atomic_int_add(AI, V) InterlockedExchangeAdd (&(AI), (V)) |
64 | 52 |
65 #define hb_atomic_ptr_get(P)» » (HBMemoryBarrier (), (void *) *(P)) | 53 #define hb_atomic_ptr_get(P)» » (MemoryBarrier (), (void *) *(P)) |
66 #define hb_atomic_ptr_cmpexch(P,O,N) (InterlockedCompareExchangePointer ((voi
d **) (P), (void *) (N), (void *) (O)) == (void *) (O)) | 54 #define hb_atomic_ptr_cmpexch(P,O,N) (InterlockedCompareExchangePointer ((voi
d **) (P), (void *) (N), (void *) (O)) == (void *) (O)) |
67 | 55 |
68 | 56 |
69 #elif !defined(HB_NO_MT) && defined(__APPLE__) | 57 #elif !defined(HB_NO_MT) && defined(__APPLE__) |
70 | 58 |
71 #include <libkern/OSAtomic.h> | 59 #include <libkern/OSAtomic.h> |
72 #ifdef __MAC_OS_X_MIN_REQUIRED | 60 #ifdef __MAC_OS_X_MIN_REQUIRED |
73 #include <AvailabilityMacros.h> | 61 #include <AvailabilityMacros.h> |
74 #elif defined(__IPHONE_OS_MIN_REQUIRED) | 62 #elif defined(__IPHONE_OS_MIN_REQUIRED) |
75 #include <Availability.h> | 63 #include <Availability.h> |
(...skipping 16 matching lines...) Expand all Loading... |
92 | 80 |
93 #elif !defined(HB_NO_MT) && defined(HAVE_INTEL_ATOMIC_PRIMITIVES) | 81 #elif !defined(HB_NO_MT) && defined(HAVE_INTEL_ATOMIC_PRIMITIVES) |
94 | 82 |
95 typedef int hb_atomic_int_t; | 83 typedef int hb_atomic_int_t; |
96 #define hb_atomic_int_add(AI, V) __sync_fetch_and_add (&(AI), (V)) | 84 #define hb_atomic_int_add(AI, V) __sync_fetch_and_add (&(AI), (V)) |
97 | 85 |
98 #define hb_atomic_ptr_get(P) (void *) (__sync_synchronize (), *(P)) | 86 #define hb_atomic_ptr_get(P) (void *) (__sync_synchronize (), *(P)) |
99 #define hb_atomic_ptr_cmpexch(P,O,N) __sync_bool_compare_and_swap ((P), (O),
(N)) | 87 #define hb_atomic_ptr_cmpexch(P,O,N) __sync_bool_compare_and_swap ((P), (O),
(N)) |
100 | 88 |
101 | 89 |
| 90 #elif !defined(HB_NO_MT) && defined(HAVE_SOLARIS_ATOMIC_OPS) |
| 91 |
| 92 #include <atomic.h> |
| 93 #include <mbarrier.h> |
| 94 |
| 95 typedef unsigned int hb_atomic_int_t; |
| 96 #define hb_atomic_int_add(AI, V) ( ({__machine_rw_barrier ();}), atomic_a
dd_int_nv (&(AI), (V)) - (V)) |
| 97 |
| 98 #define hb_atomic_ptr_get(P) ( ({__machine_rw_barrier ();}), (void *)
*(P)) |
| 99 #define hb_atomic_ptr_cmpexch(P,O,N) ( ({__machine_rw_barrier ();}), atomic_c
as_ptr ((void **) (P), (void *) (O), (void *) (N)) == (void *) (O) ? true : fals
e) |
| 100 |
| 101 |
102 #elif !defined(HB_NO_MT) | 102 #elif !defined(HB_NO_MT) |
103 | 103 |
104 #define HB_ATOMIC_INT_NIL 1 /* Warn that fallback implementation is in use. */ | 104 #define HB_ATOMIC_INT_NIL 1 /* Warn that fallback implementation is in use. */ |
105 typedef volatile int hb_atomic_int_t; | 105 typedef volatile int hb_atomic_int_t; |
106 #define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V)) | 106 #define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V)) |
107 | 107 |
108 #define hb_atomic_ptr_get(P) ((void *) *(P)) | 108 #define hb_atomic_ptr_get(P) ((void *) *(P)) |
109 #define hb_atomic_ptr_cmpexch(P,O,N) (* (void * volatile *) (P) == (void *) (
O) ? (* (void * volatile *) (P) = (void *) (N), true) : false) | 109 #define hb_atomic_ptr_cmpexch(P,O,N) (* (void * volatile *) (P) == (void *) (
O) ? (* (void * volatile *) (P) = (void *) (N), true) : false) |
110 | 110 |
111 | 111 |
112 #else /* HB_NO_MT */ | 112 #else /* HB_NO_MT */ |
113 | 113 |
114 typedef int hb_atomic_int_t; | 114 typedef int hb_atomic_int_t; |
115 #define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V)) | 115 #define hb_atomic_int_add(AI, V) (((AI) += (V)) - (V)) |
116 | 116 |
117 #define hb_atomic_ptr_get(P) ((void *) *(P)) | 117 #define hb_atomic_ptr_get(P) ((void *) *(P)) |
118 #define hb_atomic_ptr_cmpexch(P,O,N) (* (void **) (P) == (void *) (O) ? (* (v
oid **) (P) = (void *) (N), true) : false) | 118 #define hb_atomic_ptr_cmpexch(P,O,N) (* (void **) (P) == (void *) (O) ? (* (v
oid **) (P) = (void *) (N), true) : false) |
119 | 119 |
120 #endif | 120 #endif |
121 | 121 |
122 /* TODO Add tracing. */ | 122 /* TODO Add tracing. */ |
123 | 123 |
124 #endif /* HB_ATOMIC_PRIVATE_HH */ | 124 #endif /* HB_ATOMIC_PRIVATE_HH */ |
OLD | NEW |