summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2005-09-19 14:28:39 +0000
committerCarl Worth <cworth@cworth.org>2005-09-19 14:28:39 +0000
commite39b2391717a04ccaab3367450bb01c2722736cc (patch)
tree09c1a484c277b1644606a8b4636de2c7bbe29161
parentdbe0552ed39a39133d89975ac3ba9359a766c52f (diff)
Originally: 2005-09-19 Hans Breuer <hans@breuer.org>
src/cairoint.h : win32 specific definitions for CAIRO_MUTEX_DECLARE, CAIRO_MUTEX_LOCK etc. [not based on win32 mutex but critical sections] src/cairo-win32-surface.c : add DllMain() to do global, single-threaded 'mutex' (de)initialization. No ifdefs needed, some variables would simply not be used when the respective backend would not be compiled in.
-rw-r--r--ChangeLog13
-rw-r--r--src/cairo-win32-surface.c34
-rw-r--r--src/cairoint.h10
3 files changed, 57 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 176c15489..79625622c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2005-09-19 Carl Worth <cworth@cworth.org>
+
+ Originally: 2005-09-19 Hans Breuer <hans@breuer.org>
+
+ * src/cairoint.h : win32 specific definitions for
+ CAIRO_MUTEX_DECLARE, CAIRO_MUTEX_LOCK etc. [not based on win32
+ mutex but critical sections]
+
+ * src/cairo-win32-surface.c : add DllMain() to do global,
+ single-threaded 'mutex' (de)initialization. No ifdefs needed, some
+ variables would simply not be used when the respective backend
+ would not be compiled in.
+
2005-09-18 Billy Biggs <vektor@dumbterm.net>
Bug #4414, reviewed by otaylor, cworth.
diff --git a/src/cairo-win32-surface.c b/src/cairo-win32-surface.c
index d63cb5266..82dd4ffa1 100644
--- a/src/cairo-win32-surface.c
+++ b/src/cairo-win32-surface.c
@@ -1051,3 +1051,37 @@ static const cairo_surface_backend_t cairo_win32_surface_backend = {
_cairo_win32_surface_flush,
NULL /* mark_dirty_rectangle */
};
+
+/*
+ * Without pthread, on win32 we need to initialize all the 'mutex'es
+ * before use. It is guaranteed that DllMain will get called single
+ * threaded before any other function.
+ * Initializing more than finally needed should not matter much.
+ */
+#ifndef HAVE_PTHREAD_H
+CRITICAL_SECTION cairo_toy_font_face_hash_table_mutex;
+CRITICAL_SECTION cairo_scaled_font_map_mutex;
+CRITICAL_SECTION cairo_ft_unscaled_font_map_mutex;
+
+BOOL WINAPI
+DllMain (HINSTANCE hinstDLL,
+ DWORD fdwReason,
+ LPVOID lpvReserved)
+{
+ switch (fdwReason)
+ {
+ case DLL_PROCESS_ATTACH:
+ /* every 'mutex' from CAIRO_MUTEX_DECALRE needs to be initialized here */
+ InitializeCriticalSection (&cairo_toy_font_face_hash_table_mutex);
+ InitializeCriticalSection (&cairo_scaled_font_map_mutex);
+ InitializeCriticalSection (&cairo_ft_unscaled_font_map_mutex);
+ break;
+ case DLL_PROCESS_DETACH:
+ DeleteCriticalSection (&cairo_toy_font_face_hash_table_mutex);
+ DeleteCriticalSection (&cairo_scaled_font_map_mutex);
+ DeleteCriticalSection (&cairo_ft_unscaled_font_map_mutex);
+ break;
+ }
+ return TRUE;
+}
+#endif
diff --git a/src/cairoint.h b/src/cairoint.h
index a43136bea..585f1771f 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -138,6 +138,16 @@
# define CAIRO_MUTEX_UNLOCK(name) pthread_mutex_unlock (&name)
#endif
+#if !defined(CAIRO_MUTEX_DECLARE) && defined CAIRO_HAS_WIN32_SURFACE
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+ /* the real initialization must take place in DllMain */
+# define CAIRO_MUTEX_DECLARE(name) extern CRITICAL_SECTION name;
+# define CAIRO_MUTEX_DECLARE_GLOBAL(name) extern LPCRITICAL_SECTION name;
+# define CAIRO_MUTEX_LOCK(name) EnterCriticalSection (&name)
+# define CAIRO_MUTEX_UNLOCK(name) LeaveCriticalSection (&name)
+#endif
+
#ifndef CAIRO_MUTEX_DECLARE
# warning "No mutex declarations, assuming single-threaded code"
# define CAIRO_MUTEX_DECLARE(name)