Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Pixman uses some non-standard compiler features. This file ensures |
michael@0 | 2 | * they exist |
michael@0 | 3 | * |
michael@0 | 4 | * The features are: |
michael@0 | 5 | * |
michael@0 | 6 | * FUNC must be defined to expand to the current function |
michael@0 | 7 | * PIXMAN_EXPORT should be defined to whatever is required to |
michael@0 | 8 | * export functions from a shared library |
michael@0 | 9 | * limits limits for various types must be defined |
michael@0 | 10 | * inline must be defined |
michael@0 | 11 | * force_inline must be defined |
michael@0 | 12 | */ |
michael@0 | 13 | #if defined (__GNUC__) |
michael@0 | 14 | # define FUNC ((const char*) (__PRETTY_FUNCTION__)) |
michael@0 | 15 | #elif defined (__sun) || (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) |
michael@0 | 16 | # define FUNC ((const char*) (__func__)) |
michael@0 | 17 | #else |
michael@0 | 18 | # define FUNC ((const char*) ("???")) |
michael@0 | 19 | #endif |
michael@0 | 20 | |
michael@0 | 21 | #if defined (__GNUC__) |
michael@0 | 22 | # define MAYBE_UNUSED __attribute__((unused)) |
michael@0 | 23 | #else |
michael@0 | 24 | # define MAYBE_UNUSED |
michael@0 | 25 | #endif |
michael@0 | 26 | |
michael@0 | 27 | #ifndef INT16_MIN |
michael@0 | 28 | # define INT16_MIN (-32767-1) |
michael@0 | 29 | #endif |
michael@0 | 30 | |
michael@0 | 31 | #ifndef INT16_MAX |
michael@0 | 32 | # define INT16_MAX (32767) |
michael@0 | 33 | #endif |
michael@0 | 34 | |
michael@0 | 35 | #ifndef INT32_MIN |
michael@0 | 36 | # define INT32_MIN (-2147483647-1) |
michael@0 | 37 | #endif |
michael@0 | 38 | |
michael@0 | 39 | #ifndef INT32_MAX |
michael@0 | 40 | # define INT32_MAX (2147483647) |
michael@0 | 41 | #endif |
michael@0 | 42 | |
michael@0 | 43 | #ifndef UINT32_MIN |
michael@0 | 44 | # define UINT32_MIN (0) |
michael@0 | 45 | #endif |
michael@0 | 46 | |
michael@0 | 47 | #ifndef UINT32_MAX |
michael@0 | 48 | # define UINT32_MAX (4294967295U) |
michael@0 | 49 | #endif |
michael@0 | 50 | |
michael@0 | 51 | #ifndef INT64_MIN |
michael@0 | 52 | # define INT64_MIN (-9223372036854775807-1) |
michael@0 | 53 | #endif |
michael@0 | 54 | |
michael@0 | 55 | #ifndef INT64_MAX |
michael@0 | 56 | # define INT64_MAX (9223372036854775807) |
michael@0 | 57 | #endif |
michael@0 | 58 | |
michael@0 | 59 | #ifndef SIZE_MAX |
michael@0 | 60 | # define SIZE_MAX ((size_t)-1) |
michael@0 | 61 | #endif |
michael@0 | 62 | |
michael@0 | 63 | |
michael@0 | 64 | #ifndef M_PI |
michael@0 | 65 | # define M_PI 3.14159265358979323846 |
michael@0 | 66 | #endif |
michael@0 | 67 | |
michael@0 | 68 | #ifdef _MSC_VER |
michael@0 | 69 | /* 'inline' is available only in C++ in MSVC */ |
michael@0 | 70 | # define inline __inline |
michael@0 | 71 | # define force_inline __forceinline |
michael@0 | 72 | # define noinline __declspec(noinline) |
michael@0 | 73 | #elif defined __GNUC__ || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) |
michael@0 | 74 | # define inline __inline__ |
michael@0 | 75 | # define force_inline __inline__ __attribute__ ((__always_inline__)) |
michael@0 | 76 | # define noinline __attribute__((noinline)) |
michael@0 | 77 | #else |
michael@0 | 78 | # ifndef force_inline |
michael@0 | 79 | # define force_inline inline |
michael@0 | 80 | # endif |
michael@0 | 81 | # ifndef noinline |
michael@0 | 82 | # define noinline |
michael@0 | 83 | # endif |
michael@0 | 84 | #endif |
michael@0 | 85 | |
michael@0 | 86 | /* In libxul builds we don't ever want to export pixman symbols */ |
michael@0 | 87 | #if 1 |
michael@0 | 88 | #include "prcpucfg.h" |
michael@0 | 89 | |
michael@0 | 90 | #ifdef HAVE_VISIBILITY_HIDDEN_ATTRIBUTE |
michael@0 | 91 | #define CVISIBILITY_HIDDEN __attribute__((visibility("hidden"))) |
michael@0 | 92 | #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550) |
michael@0 | 93 | #define CVISIBILITY_HIDDEN __hidden |
michael@0 | 94 | #else |
michael@0 | 95 | #define CVISIBILITY_HIDDEN |
michael@0 | 96 | #endif |
michael@0 | 97 | |
michael@0 | 98 | /* In libxul builds we don't ever want to export cairo symbols */ |
michael@0 | 99 | #define PIXMAN_EXPORT extern CVISIBILITY_HIDDEN |
michael@0 | 100 | |
michael@0 | 101 | #else |
michael@0 | 102 | |
michael@0 | 103 | /* GCC visibility */ |
michael@0 | 104 | #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(_WIN32) |
michael@0 | 105 | # define PIXMAN_EXPORT __attribute__ ((visibility("default"))) |
michael@0 | 106 | /* Sun Studio 8 visibility */ |
michael@0 | 107 | #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550) |
michael@0 | 108 | # define PIXMAN_EXPORT __global |
michael@0 | 109 | #else |
michael@0 | 110 | # define PIXMAN_EXPORT |
michael@0 | 111 | #endif |
michael@0 | 112 | |
michael@0 | 113 | #endif |
michael@0 | 114 | |
michael@0 | 115 | /* member offsets */ |
michael@0 | 116 | #define CONTAINER_OF(type, member, data) \ |
michael@0 | 117 | ((type *)(((uint8_t *)data) - offsetof (type, member))) |
michael@0 | 118 | |
michael@0 | 119 | /* TLS */ |
michael@0 | 120 | #if defined(PIXMAN_NO_TLS) |
michael@0 | 121 | |
michael@0 | 122 | # define PIXMAN_DEFINE_THREAD_LOCAL(type, name) \ |
michael@0 | 123 | static type name |
michael@0 | 124 | # define PIXMAN_GET_THREAD_LOCAL(name) \ |
michael@0 | 125 | (&name) |
michael@0 | 126 | |
michael@0 | 127 | #elif defined(TLS) |
michael@0 | 128 | |
michael@0 | 129 | # define PIXMAN_DEFINE_THREAD_LOCAL(type, name) \ |
michael@0 | 130 | static TLS type name |
michael@0 | 131 | # define PIXMAN_GET_THREAD_LOCAL(name) \ |
michael@0 | 132 | (&name) |
michael@0 | 133 | |
michael@0 | 134 | #elif defined(__MINGW32__) || defined(PIXMAN_USE_XP_DLL_TLS_WORKAROUND) |
michael@0 | 135 | |
michael@0 | 136 | # define _NO_W32_PSEUDO_MODIFIERS |
michael@0 | 137 | # include <windows.h> |
michael@0 | 138 | #undef IN |
michael@0 | 139 | #undef OUT |
michael@0 | 140 | |
michael@0 | 141 | # define PIXMAN_DEFINE_THREAD_LOCAL(type, name) \ |
michael@0 | 142 | static volatile int tls_ ## name ## _initialized = 0; \ |
michael@0 | 143 | static void *tls_ ## name ## _mutex = NULL; \ |
michael@0 | 144 | static unsigned tls_ ## name ## _index; \ |
michael@0 | 145 | \ |
michael@0 | 146 | static type * \ |
michael@0 | 147 | tls_ ## name ## _alloc (void) \ |
michael@0 | 148 | { \ |
michael@0 | 149 | type *value = calloc (1, sizeof (type)); \ |
michael@0 | 150 | if (value) \ |
michael@0 | 151 | TlsSetValue (tls_ ## name ## _index, value); \ |
michael@0 | 152 | return value; \ |
michael@0 | 153 | } \ |
michael@0 | 154 | \ |
michael@0 | 155 | static force_inline type * \ |
michael@0 | 156 | tls_ ## name ## _get (void) \ |
michael@0 | 157 | { \ |
michael@0 | 158 | type *value; \ |
michael@0 | 159 | if (!tls_ ## name ## _initialized) \ |
michael@0 | 160 | { \ |
michael@0 | 161 | if (!tls_ ## name ## _mutex) \ |
michael@0 | 162 | { \ |
michael@0 | 163 | void *mutex = CreateMutexA (NULL, 0, NULL); \ |
michael@0 | 164 | if (InterlockedCompareExchangePointer ( \ |
michael@0 | 165 | &tls_ ## name ## _mutex, mutex, NULL) != NULL) \ |
michael@0 | 166 | { \ |
michael@0 | 167 | CloseHandle (mutex); \ |
michael@0 | 168 | } \ |
michael@0 | 169 | } \ |
michael@0 | 170 | WaitForSingleObject (tls_ ## name ## _mutex, 0xFFFFFFFF); \ |
michael@0 | 171 | if (!tls_ ## name ## _initialized) \ |
michael@0 | 172 | { \ |
michael@0 | 173 | tls_ ## name ## _index = TlsAlloc (); \ |
michael@0 | 174 | tls_ ## name ## _initialized = 1; \ |
michael@0 | 175 | } \ |
michael@0 | 176 | ReleaseMutex (tls_ ## name ## _mutex); \ |
michael@0 | 177 | } \ |
michael@0 | 178 | if (tls_ ## name ## _index == 0xFFFFFFFF) \ |
michael@0 | 179 | return NULL; \ |
michael@0 | 180 | value = TlsGetValue (tls_ ## name ## _index); \ |
michael@0 | 181 | if (!value) \ |
michael@0 | 182 | value = tls_ ## name ## _alloc (); \ |
michael@0 | 183 | return value; \ |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | # define PIXMAN_GET_THREAD_LOCAL(name) \ |
michael@0 | 187 | tls_ ## name ## _get () |
michael@0 | 188 | |
michael@0 | 189 | #elif defined(_MSC_VER) |
michael@0 | 190 | |
michael@0 | 191 | # define PIXMAN_DEFINE_THREAD_LOCAL(type, name) \ |
michael@0 | 192 | static __declspec(thread) type name |
michael@0 | 193 | # define PIXMAN_GET_THREAD_LOCAL(name) \ |
michael@0 | 194 | (&name) |
michael@0 | 195 | |
michael@0 | 196 | #elif defined(HAVE_PTHREAD_SETSPECIFIC) |
michael@0 | 197 | |
michael@0 | 198 | #include <pthread.h> |
michael@0 | 199 | |
michael@0 | 200 | # define PIXMAN_DEFINE_THREAD_LOCAL(type, name) \ |
michael@0 | 201 | static pthread_once_t tls_ ## name ## _once_control = PTHREAD_ONCE_INIT; \ |
michael@0 | 202 | static pthread_key_t tls_ ## name ## _key; \ |
michael@0 | 203 | \ |
michael@0 | 204 | static void \ |
michael@0 | 205 | tls_ ## name ## _destroy_value (void *value) \ |
michael@0 | 206 | { \ |
michael@0 | 207 | free (value); \ |
michael@0 | 208 | } \ |
michael@0 | 209 | \ |
michael@0 | 210 | static void \ |
michael@0 | 211 | tls_ ## name ## _make_key (void) \ |
michael@0 | 212 | { \ |
michael@0 | 213 | pthread_key_create (&tls_ ## name ## _key, \ |
michael@0 | 214 | tls_ ## name ## _destroy_value); \ |
michael@0 | 215 | } \ |
michael@0 | 216 | \ |
michael@0 | 217 | static type * \ |
michael@0 | 218 | tls_ ## name ## _alloc (void) \ |
michael@0 | 219 | { \ |
michael@0 | 220 | type *value = calloc (1, sizeof (type)); \ |
michael@0 | 221 | if (value) \ |
michael@0 | 222 | pthread_setspecific (tls_ ## name ## _key, value); \ |
michael@0 | 223 | return value; \ |
michael@0 | 224 | } \ |
michael@0 | 225 | \ |
michael@0 | 226 | static force_inline type * \ |
michael@0 | 227 | tls_ ## name ## _get (void) \ |
michael@0 | 228 | { \ |
michael@0 | 229 | type *value = NULL; \ |
michael@0 | 230 | if (pthread_once (&tls_ ## name ## _once_control, \ |
michael@0 | 231 | tls_ ## name ## _make_key) == 0) \ |
michael@0 | 232 | { \ |
michael@0 | 233 | value = pthread_getspecific (tls_ ## name ## _key); \ |
michael@0 | 234 | if (!value) \ |
michael@0 | 235 | value = tls_ ## name ## _alloc (); \ |
michael@0 | 236 | } \ |
michael@0 | 237 | return value; \ |
michael@0 | 238 | } |
michael@0 | 239 | |
michael@0 | 240 | # define PIXMAN_GET_THREAD_LOCAL(name) \ |
michael@0 | 241 | tls_ ## name ## _get () |
michael@0 | 242 | |
michael@0 | 243 | #else |
michael@0 | 244 | |
michael@0 | 245 | # error "Unknown thread local support for this system. Pixman will not work with multiple threads. Define PIXMAN_NO_TLS to acknowledge and accept this limitation and compile pixman without thread-safety support." |
michael@0 | 246 | |
michael@0 | 247 | #endif |