summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pixman/pixman-private.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h
index 9dcdca78..857e035e 100644
--- a/pixman/pixman-private.h
+++ b/pixman/pixman-private.h
@@ -805,6 +805,82 @@ _pixman_log_error (const char *function, const char *message);
#endif
/*
+ * Thread primitives
+ */
+
+/* Atomic accessors */
+
+#if defined (WIN32) || !defined(ATOMIC_OPS_REQUIRE_MEMORY_BARRIER)
+
+#define PIXMAN_ATOMIC_POINTER_GET(atomic) \
+ (*(void **)(atomic))
+#define PIXMAN_ATOMIC_POINTER_SET(atomic,value) \
+ ((*(void **)(atomic)) = (value))
+#define PIXMAN_ATOMIC_INT_GET(atomic) \
+ (*(int *)(atomic))
+#define PIXMAN_ATOMIC_INT_SET(atomic, value) \
+ (*(int *)(atomic))
+
+#else
+
+#define PIXMAN_ATOMIC_POINTER_GET(atomic) \
+ (_pixman_atomic_pointer_get ((atomic)))
+#define PIXMAN_ATOMIC_POINTER_SET(atomic, value) \
+ (_pixman_atomic_pointer_set ((atomic), (value)))
+#define PIXMAN_ATOMIC_INT_GET(atomic) \
+ (_pixman_atomic_int_get ((atomic)))
+#define PIXMAN_ATOMIC_INT_SET(atomic, value) \
+ (_pixman_atomic_int_set ((atomic), (value)))
+
+#endif
+
+/* Mutexes */
+
+#if defined (WIN32)
+
+#include <windows.h>
+
+#define PIXMAN_DEFINE_LOCK(name) \
+ static CRITICAL_SECTION __ ## name ## _critical_section; \
+ static CRITICAL_SECTION *__ ## name ## _ptr;
+
+#define PIXMAN_LOCK(name) \
+ if (!PIXMAN_ATOMIC_POINTER_GET ((void **)&__ ## name ## _ptr)) \
+ { \
+ _pixman_win32_initialize_critical_section ( \
+ &__ ## name ## _ptr, \
+ &__ ## name ## _critical_section); \
+ } \
+ \
+ EnterCriticalSection(&__ ## name ## _critical_section)
+
+#define PIXMAN_UNLOCK(name) \
+ LeaveCriticalSection(&__ ## name ## _critical_section)
+
+#else
+
+#define PIXMAN_DEFINE_LOCK(name) \
+ static pthread_mutex_t __ ## name ## _mutex = \
+ PTHREAD_MUTEX_INITIALIZER;
+
+#define PIXMAN_LOCK(name) \
+ pthread_mutex_lock(&__ ## name ## _mutex)
+
+#define PIXMAN_UNLOCK(name) \
+ pthread_mutex_unlock(&__ ## name ## _mutex)
+
+#endif
+
+/* Atomic operations */
+
+#if 0 /* FIXME define these */
+PIXMAN_ATOMIC_POINTER_CMPXCHG()
+PIXMAN_ATOMIC_INT_DEC_AND_TEST(atomic *a)
+PIXMAN_ATOMIC_INT_CMPXCHG(atomic, ...)
+#endif
+
+
+/*
* Timers
*/