1 /* Pixman uses some non-standard compiler features. This file ensures
6 * FUNC must be defined to expand to the current function
7 * PIXMAN_EXPORT should be defined to whatever is required to
8 * export functions from a shared library
9 * limits limits for various types must be defined
10 * inline must be defined
11 * force_inline must be defined
13 #if defined (__GNUC__)
14 # define FUNC ((const char*) (__PRETTY_FUNCTION__))
15 #elif defined (__sun) || (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
16 # define FUNC ((const char*) (__func__))
18 # define FUNC ((const char*) ("???"))
21 #if defined (__GNUC__)
22 # define MAYBE_UNUSED __attribute__((unused))
28 # define INT16_MIN (-32767-1)
32 # define INT16_MAX (32767)
36 # define INT32_MIN (-2147483647-1)
40 # define INT32_MAX (2147483647)
44 # define UINT32_MIN (0)
48 # define UINT32_MAX (4294967295U)
52 # define INT64_MIN (-9223372036854775807-1)
56 # define INT64_MAX (9223372036854775807)
61 # define M_PI 3.14159265358979323846
65 /* 'inline' is available only in C++ in MSVC */
66 # define inline __inline
67 # define force_inline __forceinline
68 # define noinline __declspec(noinline)
69 #elif defined __GNUC__ || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
70 # define inline __inline__
71 # define force_inline __inline__ __attribute__ ((__always_inline__))
72 # define noinline __attribute__((noinline))
75 # define force_inline inline
83 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(_WIN32)
84 # define PIXMAN_EXPORT __attribute__ ((visibility("default")))
85 /* Sun Studio 8 visibility */
86 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
87 # define PIXMAN_EXPORT __global
89 # define PIXMAN_EXPORT
93 #if defined(PIXMAN_NO_TLS)
95 # define PIXMAN_DEFINE_THREAD_LOCAL(type, name) \
97 # define PIXMAN_GET_THREAD_LOCAL(name) \
102 # define PIXMAN_DEFINE_THREAD_LOCAL(type, name) \
104 # define PIXMAN_GET_THREAD_LOCAL(name) \
107 #elif defined(__MINGW32__)
109 # define _NO_W32_PSEUDO_MODIFIERS
110 # include <windows.h>
112 # define PIXMAN_DEFINE_THREAD_LOCAL(type, name) \
113 static volatile int tls_ ## name ## _initialized = 0; \
114 static void *tls_ ## name ## _mutex = NULL; \
115 static unsigned tls_ ## name ## _index; \
118 tls_ ## name ## _alloc (void) \
120 type *value = calloc (1, sizeof (type)); \
122 TlsSetValue (tls_ ## name ## _index, value); \
126 static force_inline type * \
127 tls_ ## name ## _get (void) \
130 if (!tls_ ## name ## _initialized) \
132 if (!tls_ ## name ## _mutex) \
134 void *mutex = CreateMutexA (NULL, 0, NULL); \
135 if (InterlockedCompareExchangePointer ( \
136 &tls_ ## name ## _mutex, mutex, NULL) != NULL) \
138 CloseHandle (mutex); \
141 WaitForSingleObject (tls_ ## name ## _mutex, 0xFFFFFFFF); \
142 if (!tls_ ## name ## _initialized) \
144 tls_ ## name ## _index = TlsAlloc (); \
145 tls_ ## name ## _initialized = 1; \
147 ReleaseMutex (tls_ ## name ## _mutex); \
149 if (tls_ ## name ## _index == 0xFFFFFFFF) \
151 value = TlsGetValue (tls_ ## name ## _index); \
153 value = tls_ ## name ## _alloc (); \
157 # define PIXMAN_GET_THREAD_LOCAL(name) \
158 tls_ ## name ## _get ()
160 #elif defined(_MSC_VER)
162 # define PIXMAN_DEFINE_THREAD_LOCAL(type, name) \
163 static __declspec(thread) type name
164 # define PIXMAN_GET_THREAD_LOCAL(name) \
167 #elif defined(HAVE_PTHREAD_SETSPECIFIC)
171 # define PIXMAN_DEFINE_THREAD_LOCAL(type, name) \
172 static pthread_once_t tls_ ## name ## _once_control = PTHREAD_ONCE_INIT; \
173 static pthread_key_t tls_ ## name ## _key; \
176 tls_ ## name ## _destroy_value (void *value) \
182 tls_ ## name ## _make_key (void) \
184 pthread_key_create (&tls_ ## name ## _key, \
185 tls_ ## name ## _destroy_value); \
189 tls_ ## name ## _alloc (void) \
191 type *value = calloc (1, sizeof (type)); \
193 pthread_setspecific (tls_ ## name ## _key, value); \
197 static force_inline type * \
198 tls_ ## name ## _get (void) \
200 type *value = NULL; \
201 if (pthread_once (&tls_ ## name ## _once_control, \
202 tls_ ## name ## _make_key) == 0) \
204 value = pthread_getspecific (tls_ ## name ## _key); \
206 value = tls_ ## name ## _alloc (); \
211 # define PIXMAN_GET_THREAD_LOCAL(name) \
212 tls_ ## name ## _get ()
216 # 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."