[cairo-commit] cairo/src cairo-win32-surface.c, 1.34, 1.34.2.1 cairoint.h, 1.207, 1.207.2.1

Carl Worth commit at pdx.freedesktop.org
Mon Sep 19 14:28:42 PDT 2005


Committed by: cworth

Update of /cvs/cairo/cairo/src
In directory gabe:/tmp/cvs-serv20428/src

Modified Files:
      Tag: BRANCH_1_0
	cairo-win32-surface.c cairoint.h 
Log Message:

2005-09-19  Carl Worth  <cworth at cworth.org>

        Originally: 2005-09-19  Hans Breuer  <hans at 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.


Index: cairo-win32-surface.c
===================================================================
RCS file: /cvs/cairo/cairo/src/cairo-win32-surface.c,v
retrieving revision 1.34
retrieving revision 1.34.2.1
diff -u -d -r1.34 -r1.34.2.1
--- cairo-win32-surface.c	23 Aug 2005 21:30:52 -0000	1.34
+++ cairo-win32-surface.c	19 Sep 2005 21:28:39 -0000	1.34.2.1
@@ -1051,3 +1051,37 @@
     _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

Index: cairoint.h
===================================================================
RCS file: /cvs/cairo/cairo/src/cairoint.h,v
retrieving revision 1.207
retrieving revision 1.207.2.1
diff -u -d -r1.207 -r1.207.2.1
--- cairoint.h	28 Aug 2005 01:46:34 -0000	1.207
+++ cairoint.h	19 Sep 2005 21:28:39 -0000	1.207.2.1
@@ -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)



More information about the cairo-commit mailing list