[Pixman] [PATCH 1/8] Add platform specific mutex implementations
Taekyun Kim
podain77 at gmail.com
Mon Sep 19 07:08:19 PDT 2011
From: Taekyun Kim <tkq.kim at samsung.com>
Declare mutex with type of pixman_mutex_t and use following macros.
PIXMAN_MUTEX_INIT()
PIXMAN_MUTEX_LOCK()
PIXMAN_MUTEX_UNLOCK()
PIXMAN_MUTEX_FINI()
If any mutex implemenatation is supported by the system, HAVE_MUTEX
macro will be defined.
---
configure.ac | 3 +++
pixman/pixman-compiler.h | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/configure.ac b/configure.ac
index dc523df..8771ec9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -679,6 +679,9 @@ if test x$have_gettimeofday = xyes && test x$have_sys_time_h = xyes; then
AC_DEFINE(HAVE_GETTIMEOFDAY, 1, [Whether we have gettimeofday()])
fi
+AC_CHECK_HEADER([pthread.h],
+ [AC_DEFINE(HAVE_PTHREAD_H, [1], [Define to 1 if we have <pthread.h>])])
+
dnl =====================================
dnl Thread local storage
diff --git a/pixman/pixman-compiler.h b/pixman/pixman-compiler.h
index fe2a613..47e68c5 100644
--- a/pixman/pixman-compiler.h
+++ b/pixman/pixman-compiler.h
@@ -207,3 +207,42 @@
# 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."
#endif
+
+#if defined(HAVE_PTHREAD_H)
+
+# include <pthread.h>
+
+typedef pthread_mutex_t pixman_mutex_t;
+
+# define PIXMAN_MUTEX_INIT(mutex) pthread_mutex_init (&(mutex), NULL)
+# define PIXMAN_MUTEX_LOCK(mutex) pthread_mutex_lock (&(mutex))
+# define PIXMAN_MUTEX_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
+# define PIXMAN_MUTEX_FINI(mutex) pthread_mutex_destroy (&(mutex))
+
+# define HAVE_MUTEX 1
+
+#elif defined(_WIN32)
+
+# include <windows.h>
+
+typedef CRITICAL_SECTION pixman_mutex_t;
+
+# define PIXMAN_MUTEX_INIT(mutex) InitializeCriticalSection (&(mutex))
+# define PIXMAN_MUTEX_LOCK(mutex) EnterCriticalSection (&(mutex))
+# define PIXMAN_MUTEX_UNLOCK(mutex) LeaveCriticalSection (&(mutex))
+# define PIXMAN_MUTEX_FINI(mutex) DeleteCriticalSection (&(mutex))
+
+# define HAVE_MUTEX 1
+
+#else
+
+typedef int pixman_mutex_t;
+
+# define PIXMAN_MUTEX_INIT(mutex) do while (0) {}
+# define PIXMAN_MUTEX_LOCK(mutex) do while (0) {}
+# define PIXMAN_MUTEX_UNLOCK(mutex) do while (0) {}
+# define PIXMAN_MUTEX_FINI(mutex) do while (0) {}
+
+# warning "Unknown mutex support for this system. Pixman will work without mutex support."
+
+#endif
--
1.7.1
More information about the Pixman
mailing list