[cairo] Re: Sorry I broke the text tests! (and status update)

Mathias Hasselmann mathias.hasselmann at gmx.de
Fri Mar 9 13:43:20 PST 2007


Am Montag, den 05.03.2007, 15:01 -0500 schrieb Behdad Esfahbod:
>   - all non-public headers should end in "-private.h".  This is relied
> on in the documentation generation stuff.  We talked about moving to a
> scheme that all non-public headers don't start with "cairo-", but that's
> not been done so far.
> 
>   - Please rename all mutexes to be in the shape "_cairo_*_mutex", since
> they are not static anymore.  We can go a bit further and make the
> CAIRO_MUTEX_* macros do the namespacing for us, but we typically avoid
> name mangling in cairo. 

As we missunderstood on IRC you did the renaming already. So I've
produced some updated patch set.
-------------- next part --------------
>From a2ea122c049ce4477651ed7efbb3266d9d4c6a0c Mon Sep 17 00:00:00 2001
From: Mathias Hasselmann <mathias.hasselmann at gmx.de>
Date: Mon, 5 Mar 2007 08:36:26 +0100
Subject: [PATCH] [PATCH] Remove problems causing -Werror to fail

Expect for the problems gcc 3.4.5/mingw finds in cairo-png.c and
expect for the problems gcc 4.1.2 finds in cairo-directfb-surface.c.
---
 boilerplate/cairo-boilerplate.c |   24 +++++++++++++++---------
 src/cairo-font.c                |    2 +-
 src/cairo-image-surface.c       |   14 +++++++++++++-
 src/cairo-matrix.c              |    3 +++
 src/cairo-pattern.c             |   30 ++++++++++++++++--------------
 src/cairo-scaled-font.c         |    2 +-
 src/cairo-surface.c             |    1 +
 src/cairo-svg-surface.c         |    3 ++-
 src/cairo-win32-surface.c       |   13 +++++++++++--
 src/cairo.c                     |    2 +-
 src/cairoint.h                  |    2 +-
 test/pdiff/pdiff.c              |    3 ++-
 12 files changed, 67 insertions(+), 32 deletions(-)

diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index 561e6df..791ca3d 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -1369,9 +1369,9 @@ cairo_boilerplate_target_t targets[] =
      * for tolerance. There shouldn't ever be anything that is out of
      * our control here. */
     { "image", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR_ALPHA, 0,
-      create_image_surface, cairo_surface_write_to_png, NULL},
+      create_image_surface, cairo_surface_write_to_png, NULL, NULL, NULL},
     { "image", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR, 0,
-      create_image_surface, cairo_surface_write_to_png, NULL},
+      create_image_surface, cairo_surface_write_to_png, NULL, NULL, NULL},
 #ifdef CAIRO_HAS_TEST_SURFACES
     { "test-fallback", CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK,
       CAIRO_CONTENT_COLOR_ALPHA, 0,
@@ -1432,9 +1432,11 @@ cairo_boilerplate_target_t targets[] =
 #endif
 #if CAIRO_HAS_WIN32_SURFACE
     { "win32", CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR, 0,
-      create_win32_surface, cairo_surface_write_to_png, cleanup_win32 },
+      create_win32_surface, cairo_surface_write_to_png, cleanup_win32,
+      NULL, NULL },
     { "win32", CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR_ALPHA, 0,
-      create_win32_surface, cairo_surface_write_to_png, cleanup_win32 },
+      create_win32_surface, cairo_surface_write_to_png, cleanup_win32,
+      NULL, NULL },
 #endif
 #if CAIRO_HAS_XCB_SURFACE
     /* Acceleration architectures may make the results differ by a
@@ -1456,7 +1458,8 @@ cairo_boilerplate_target_t targets[] =
 #if CAIRO_HAS_PS_SURFACE
     { "ps", CAIRO_SURFACE_TYPE_PS,
       CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED, 0,
-      create_ps_surface, ps_surface_write_to_png, cleanup_ps },
+      create_ps_surface, ps_surface_write_to_png, cleanup_ps,
+      NULL, NULL },
 
     /* XXX: We expect type image here only due to a limitation in
      * the current PS/meta-surface code. A PS surface is
@@ -1467,7 +1470,8 @@ cairo_boilerplate_target_t targets[] =
      * create_similar path for all paginated surfaces currently
      * returns an image surface.*/
     { "ps", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR, 0,
-      create_ps_surface, ps_surface_write_to_png, cleanup_ps },
+      create_ps_surface, ps_surface_write_to_png, cleanup_ps,
+      NULL, NULL },
 #endif
 #if CAIRO_HAS_PDF_SURFACE && CAIRO_CAN_TEST_PDF_SURFACE
     { "pdf", CAIRO_SURFACE_TYPE_PDF,
@@ -1492,9 +1496,11 @@ cairo_boilerplate_target_t targets[] =
      * tests. XXX: I'd still like to chase these down at some point.
      * For now just set the svg error tolerance to 1. */
     { "svg", CAIRO_SURFACE_TYPE_SVG, CAIRO_CONTENT_COLOR_ALPHA, 1,
-      create_svg_surface, svg_surface_write_to_png, cleanup_svg },
+      create_svg_surface, svg_surface_write_to_png, cleanup_svg,
+      NULL, NULL },
     { "svg", CAIRO_INTERNAL_SURFACE_TYPE_META, CAIRO_CONTENT_COLOR, 1,
-      create_svg_surface, svg_surface_write_to_png, cleanup_svg },
+      create_svg_surface, svg_surface_write_to_png, cleanup_svg,
+      NULL, NULL },
 #endif
 #if CAIRO_HAS_BEOS_SURFACE
     /* BeOS sometimes produces a slightly different image. Perhaps this
@@ -1515,7 +1521,7 @@ cairo_boilerplate_target_t targets[] =
       create_directfb_surface, cairo_surface_write_to_png,cleanup_directfb},
 #endif
 
-    { NULL }
+    { NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
 };
 
 void
diff --git a/src/cairo-font.c b/src/cairo-font.c
index cacc589..4b768fb 100644
--- a/src/cairo-font.c
+++ b/src/cairo-font.c
@@ -51,7 +51,7 @@ const cairo_font_face_t _cairo_font_face_nil = {
     { 0 },			/* hash_entry */
     CAIRO_STATUS_NO_MEMORY,	/* status */
     CAIRO_REF_COUNT_INVALID,	/* ref_count */
-    { 0, 0, 0, NULL },		/* user_data */
+    { 0, 0, 0, NULL, FALSE },   /* user_data */
     &_cairo_toy_font_face_backend
 };
 
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 6279012..c8e77ea 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -48,6 +48,7 @@ const cairo_image_surface_t _cairo_image_surface_nil_invalid_format = {
 	  0,	/* num_elements */
 	  0,	/* element_size */
 	  NULL,	/* elements */
+	  FALSE /* is_snapshot */
 	},				/* user_data */
 	{ 1.0, 0.0,
 	  0.0, 1.0,
@@ -1099,7 +1100,18 @@ const cairo_surface_backend_t cairo_image_surface_backend = {
     _cairo_image_surface_set_clip_region,
     NULL, /* intersect_clip_path */
     _cairo_image_surface_get_extents,
-    NULL /* old_show_glyphs */
+    NULL, /* old_show_glyphs */
+    NULL, /* get_font_options */
+    NULL, /* flush */
+    NULL, /* mark_dirty_rectangle */
+    NULL, /* scaled_font_fini */
+    NULL, /* scaled_glyph_fini */
+    NULL, /* paint */
+    NULL, /* mask */
+    NULL, /* stroke */
+    NULL, /* fill */
+    NULL, /* show_glyphs */
+    NULL  /* snapshot */
 };
 
 /* A convenience function for when one needs to coerce an image
diff --git a/src/cairo-matrix.c b/src/cairo-matrix.c
index b689f2a..64e4a47 100644
--- a/src/cairo-matrix.c
+++ b/src/cairo-matrix.c
@@ -34,7 +34,10 @@
  *	Carl D. Worth <cworth at cworth.org>
  */
 
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
+
 #include <stdlib.h>
 
 #include "cairoint.h"
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index efa0c5a..ad5b348 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -31,23 +31,25 @@
 #include "cairoint.h"
 
 const cairo_solid_pattern_t cairo_pattern_nil = {
-    { CAIRO_PATTERN_TYPE_SOLID, 	/* type */
-      CAIRO_REF_COUNT_INVALID,		/* ref_count */
-      CAIRO_STATUS_NO_MEMORY,	/* status */
-      { 0, 0, 0, NULL },		/* user_data */
-      { 1., 0., 0., 1., 0., 0., }, /* matrix */
-      CAIRO_FILTER_DEFAULT,	/* filter */
-      CAIRO_EXTEND_GRADIENT_DEFAULT },	/* extend */
+    { CAIRO_PATTERN_TYPE_SOLID,         /* type */
+      CAIRO_REF_COUNT_INVALID,          /* ref_count */
+      CAIRO_STATUS_NO_MEMORY,           /* status */
+      { 0, 0, 0, NULL, FALSE },         /* user_data */
+      { 1., 0., 0., 1., 0., 0., },      /* matrix */
+      CAIRO_FILTER_DEFAULT,             /* filter */
+      CAIRO_EXTEND_GRADIENT_DEFAULT },  /* extend */
+    { 0, 0, 0, 0, 0, 0, 0, 0 }          /* color */
 };
 
 static const cairo_solid_pattern_t cairo_pattern_nil_null_pointer = {
-    { CAIRO_PATTERN_TYPE_SOLID, 	/* type */
-      CAIRO_REF_COUNT_INVALID,		/* ref_count */
-      CAIRO_STATUS_NULL_POINTER,/* status */
-      { 0, 0, 0, NULL },		/* user_data */
-      { 1., 0., 0., 1., 0., 0., }, /* matrix */
-      CAIRO_FILTER_DEFAULT,	/* filter */
-      CAIRO_EXTEND_GRADIENT_DEFAULT },	/* extend */
+    { CAIRO_PATTERN_TYPE_SOLID,         /* type */
+      CAIRO_REF_COUNT_INVALID,          /* ref_count */
+      CAIRO_STATUS_NULL_POINTER,        /* status */
+      { 0, 0, 0, NULL, FALSE },         /* user_data */
+      { 1., 0., 0., 1., 0., 0., },      /* matrix */
+      CAIRO_FILTER_DEFAULT,             /* filter */
+      CAIRO_EXTEND_GRADIENT_DEFAULT },  /* extend */
+    { 0, 0, 0, 0, 0, 0, 0, 0 }          /* color */
 };
 
 /**
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 0162a0d..f3b126e 100755
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -75,7 +75,7 @@ const cairo_scaled_font_t _cairo_scaled_font_nil = {
     { 0 },			/* hash_entry */
     CAIRO_STATUS_NO_MEMORY,	/* status */
     CAIRO_REF_COUNT_INVALID,	/* ref_count */
-    { 0, 0, 0, NULL },		/* user_data */
+    { 0, 0, 0, NULL, FALSE },	/* user_data */
     NULL,			/* font_face */
     { 1., 0., 0., 1., 0, 0},	/* font_matrix */
     { 1., 0., 0., 1., 0, 0},	/* ctm */
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 3162a01..f134bc2 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -53,6 +53,7 @@ const cairo_surface_t name = {					\
       0,	/* num_elements */				\
       0,	/* element_size */				\
       NULL,	/* elements */					\
+      FALSE	/* is_snapshot */				\
     },					/* user_data */		\
     { 1.0, 0.0,							\
       0.0, 1.0,							\
diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 5cb9ce0..049741a 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -2016,7 +2016,8 @@ static const cairo_surface_backend_t cairo_svg_surface_backend = {
 	_cairo_svg_surface_mask,
 	_cairo_svg_surface_stroke,
 	_cairo_svg_surface_fill,
-	_cairo_svg_surface_show_glyphs
+	_cairo_svg_surface_show_glyphs,
+        NULL /* snapshot */
 };
 
 static cairo_svg_document_t *
diff --git a/src/cairo-win32-surface.c b/src/cairo-win32-surface.c
index 9123b82..f0b75d0 100644
--- a/src/cairo-win32-surface.c
+++ b/src/cairo-win32-surface.c
@@ -835,7 +835,7 @@ _cairo_win32_surface_composite (cairo_operator_t	op,
     int alpha;
     double scalex, scaley;
     cairo_fixed_t x0_fixed, y0_fixed;
-    cairo_int_status_t status;
+    cairo_int_status_t status = CAIRO_STATUS_SUCCESS;
 
     cairo_bool_t needs_alpha, needs_scale, needs_repeat;
     cairo_image_surface_t *src_image = NULL;
@@ -982,7 +982,7 @@ _cairo_win32_surface_composite (cairo_operator_t	op,
 	 * we can't do anything useful here.
 	 */
 	if (src_r.x > src_extents.width || src_r.y > src_extents.height ||
-	    (src_r.x + src_r.width) < 0 || (src_r.y + src_r.height) < 0)
+	    (int)(src_r.x + src_r.width) < 0 || (int)(src_r.y + src_r.height) < 0)
 	{
 	    if (op == CAIRO_OPERATOR_OVER)
 		return CAIRO_STATUS_SUCCESS;
@@ -1919,6 +1919,15 @@ _cairo_win32_initialize (void) {
 }
 
 #if !defined(CAIRO_WIN32_STATIC_BUILD)
+
+/*
+ * Avoid warning regarding missing prototype
+ */
+BOOL WINAPI
+DllMain (HINSTANCE hinstDLL,
+	 DWORD     fdwReason,
+	 LPVOID    lpvReserved);
+
 BOOL WINAPI
 DllMain (HINSTANCE hinstDLL,
 	 DWORD     fdwReason,
diff --git a/src/cairo.c b/src/cairo.c
index 355fcae..4004ccf 100644
--- a/src/cairo.c
+++ b/src/cairo.c
@@ -47,7 +47,7 @@
 static const cairo_t cairo_nil = {
   CAIRO_REF_COUNT_INVALID,	/* ref_count */
   CAIRO_STATUS_NO_MEMORY,	/* status */
-  { 0, 0, 0, NULL },		/* user_data */
+  { 0, 0, 0, NULL, FALSE },	/* user_data */
   { 				/* path */
     NULL, NULL,			   /* op_buf_head, op_buf_tail */
     NULL, NULL,			   /* arg_buf_head, arg_buf_tail */
diff --git a/src/cairoint.h b/src/cairoint.h
index 3e54857..e314152 100755
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -169,7 +169,7 @@ typedef pthread_mutex_t cairo_mutex_t;
 typedef CRITICAL_SECTION cairo_mutex_t;
 # define CAIRO_MUTEX_INIT(mutex) InitializeCriticalSection (mutex)
 # define CAIRO_MUTEX_FINI(mutex) DeleteCriticalSection (mutex)
-# define CAIRO_MUTEX_NIL_INITIALIZER { 0 }
+# define CAIRO_MUTEX_NIL_INITIALIZER { NULL, 0, 0, NULL, NULL, 0 }
 #endif
 
 #if defined(__OS2__) && !defined(CAIRO_MUTEX_DECLARE)
diff --git a/test/pdiff/pdiff.c b/test/pdiff/pdiff.c
index 91e0caf..22c3a6b 100644
--- a/test/pdiff/pdiff.c
+++ b/test/pdiff/pdiff.c
@@ -13,8 +13,9 @@
   You should have received a copy of the GNU General Public License along with this program;
   if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
-
+#ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
 
 #include "lpyramid.h"
 #include <math.h>
-- 
1.4.4.2

-------------- next part --------------
>From 5af980ccd8c30b07016dfbe8f85a294f0bf63d29 Mon Sep 17 00:00:00 2001
From: Mathias Hasselmann <mathias.hasselmann at gmx.de>
Date: Mon, 5 Mar 2007 10:21:40 +0100
Subject: [PATCH] [PATCH] Initialize mutexes at central location.

---
 src/Makefile.am               |    1 +
 src/cairo-font.c              |    7 +--
 src/cairo-ft-font.c           |    3 +-
 src/cairo-mutex-list.h        |   53 ++++++++++++++++++
 src/cairo-mutex-private.h     |  118 +++++++++++++++++++++++++++++++++++++++++
 src/cairo-mutex.c             |   51 ++++++++++++++++++
 src/cairo-os2-surface.c       |   20 -------
 src/cairo-paginated-surface.c |    1 +
 src/cairo-pattern.c           |    3 +
 src/cairo-scaled-font.c       |    3 +-
 src/cairo-surface.c           |    5 +-
 src/cairo-win32-font.c        |   10 ----
 src/cairo-win32-private.h     |    3 -
 src/cairo-win32-surface.c     |   74 -------------------------
 src/cairo-xlib-screen.c       |    3 +-
 src/cairoint.h                |   71 +++++--------------------
 16 files changed, 250 insertions(+), 176 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index d2ec4cf..ce2aa6e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -188,6 +188,7 @@ libcairo_la_SOURCES =				\
 	cairo-image-surface.c			\
 	cairo-lzw.c				\
 	cairo-matrix.c				\
+	cairo-mutex.c				\
 	cairo-operator.c			\
 	cairo-path.c				\
 	cairo-path-private.h			\
diff --git a/src/cairo-font.c b/src/cairo-font.c
index 4b768fb..f2442cd 100644
--- a/src/cairo-font.c
+++ b/src/cairo-font.c
@@ -39,6 +39,7 @@
  */
 
 #include "cairoint.h"
+#include "cairo-mutex-private.h"
 
 /* Forward declare so we can use it as an arbitrary backend for
  * _cairo_font_face_nil.
@@ -59,6 +60,8 @@ void
 _cairo_font_face_init (cairo_font_face_t               *font_face,
 		       const cairo_font_face_backend_t *backend)
 {
+    CAIRO_MUTEX_INITIALIZE ();
+
     font_face->status = CAIRO_STATUS_SUCCESS;
     font_face->ref_count = 1;
     font_face->backend = backend;
@@ -66,10 +69,6 @@ _cairo_font_face_init (cairo_font_face_t               *font_face,
     _cairo_user_data_array_init (&font_face->user_data);
 }
 
-/* This mutex protects both cairo_toy_font_hash_table as well as
-   reference count manipulations for all cairo_font_face_t. */
-CAIRO_MUTEX_DECLARE (_cairo_font_face_mutex);
-
 /**
  * cairo_font_face_reference:
  * @font_face: a #cairo_font_face_t, (may be %NULL in which case this
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index 27bc2e3..d397655 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -40,6 +40,7 @@
 #include <float.h>
 
 #include "cairo-ft-private.h"
+#include "cairo-mutex-private.h"
 
 #include <fontconfig/fontconfig.h>
 #include <fontconfig/fcfreetype.h>
@@ -150,8 +151,6 @@ typedef struct _cairo_ft_unscaled_font_map {
 
 static cairo_ft_unscaled_font_map_t *cairo_ft_unscaled_font_map = NULL;
 
-CAIRO_MUTEX_DECLARE(_cairo_ft_unscaled_font_map_mutex);
-
 static void
 _font_map_release_face_lock_held (cairo_ft_unscaled_font_map_t *font_map,
 				  cairo_ft_unscaled_font_t *unscaled)
diff --git a/src/cairo-mutex-list.h b/src/cairo-mutex-list.h
new file mode 100644
index 0000000..38d305f
--- /dev/null
+++ b/src/cairo-mutex-list.h
@@ -0,0 +1,53 @@
+/* cairo - a vector graphics library with display and print output
+ *
+ * Copyright ? 2007 the cairo graphics library project
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ *
+ * The Original Code is the cairo graphics library.
+ *
+ * Contributor(s):
+ *	Mathias Hasselmann <mathias.hasselmann at gmx.de>
+ */
+
+#ifndef CAIRO_MUTEX_LIST_H
+#define CAIRO_MUTEX_LIST_H
+
+CAIRO_MUTEX_DECLARE (_cairo_font_face_mutex);
+CAIRO_MUTEX_DECLARE (_cairo_scaled_font_map_mutex);
+
+#if CAIRO_HAS_FT_FONT
+CAIRO_MUTEX_DECLARE (_cairo_ft_unscaled_font_map_mutex);
+#endif
+
+#if CAIRO_HAS_XLIB_SURFACE
+CAIRO_MUTEX_DECLARE (_xlib_screen_mutex);
+#endif
+
+#if CAIRO_HAS_OS2_SURFACE
+CAIRO_MUTEX_DECLARE (cairo_toy_font_face_hash_table_mutex);
+CAIRO_MUTEX_DECLARE (_global_image_glyph_cache_mutex);
+#endif
+
+#endif
diff --git a/src/cairo-mutex-private.h b/src/cairo-mutex-private.h
new file mode 100644
index 0000000..fdaeb8b
--- /dev/null
+++ b/src/cairo-mutex-private.h
@@ -0,0 +1,118 @@
+/* cairo - a vector graphics library with display and print output
+ *
+ * Copyright ? 2002 University of Southern California
+ * Copyright ? 2005 Red Hat, Inc.
+ * Copyright ? 2007 the cairo graphics library project
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ *
+ * The Original Code is the cairo graphics library.
+ *
+ * The Initial Developer of the Original Code is University of Southern
+ * California.
+ *
+ * Contributor(s):
+ *	Carl D. Worth <cworth at cworth.org>
+ *	Mathias Hasselmann <mathias.hasselmann at gmx.de>
+ */
+
+#ifndef CAIRO_MUTEX_PRIVATE_H
+#define CAIRO_MUTEX_PRIVATE_H
+
+#include "cairoint.h"
+
+#if HAVE_PTHREAD_H
+
+# define CAIRO_MUTEX_INITIALIZE() /* no-op */
+# define CAIRO_MUTEX_LOCK(name) pthread_mutex_lock (&name)
+# define CAIRO_MUTEX_UNLOCK(name) pthread_mutex_unlock (&name)
+# define CAIRO_MUTEX_INIT(mutex) do {				\
+    pthread_mutex_t tmp_mutex = PTHREAD_MUTEX_INITIALIZER;      \
+    memcpy (mutex, &tmp_mutex, sizeof (tmp_mutex));             \
+} while (0)
+# define CAIRO_MUTEX_FINI(mutex) pthread_mutex_destroy (mutex)
+# define CAIRO_MUTEX_NIL_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+
+#elif defined CAIRO_HAS_WIN32_SURFACE
+
+# define CAIRO_MUTEX_LOCK(name) EnterCriticalSection (&name)
+# define CAIRO_MUTEX_UNLOCK(name) LeaveCriticalSection (&name)
+# define CAIRO_MUTEX_INIT(mutex) InitializeCriticalSection (mutex)
+# define CAIRO_MUTEX_FINI(mutex) DeleteCriticalSection (mutex)
+# define CAIRO_MUTEX_NIL_INITIALIZER { NULL, 0, 0, NULL, NULL, 0 }
+
+#elif defined __OS2__
+
+# define CAIRO_MUTEX_LOCK(name) DosRequestMutexSem(name, SEM_INDEFINITE_WAIT)
+# define CAIRO_MUTEX_UNLOCK(name) DosReleaseMutexSem(name)
+# define CAIRO_MUTEX_INIT(mutex) DosCreateMutexSem (NULL, mutex, 0L, FALSE)
+# define CAIRO_MUTEX_FINI(mutex) DosCloseMutexSem (*(mutex))
+# define CAIRO_MUTEX_NIL_INITIALIZER 0
+
+#elif defined CAIRO_HAS_BEOS_SURFACE
+
+cairo_private void _cairo_beos_lock(cairo_mutex_t*);
+cairo_private void _cairo_beos_unlock(cairo_mutex_t*);
+
+/* the real initialization takes place in a global constructor */
+# define CAIRO_MUTEX_LOCK(name) _cairo_beos_lock (&name)
+# define CAIRO_MUTEX_UNLOCK(name) _cairo_beos_unlock (&name)
+
+# error "XXX: Someone who understands BeOS needs to add definitions for" \
+        "     cairo_mutex_t, CAIRO_MUTEX_INIT, and CAIRO_MUTEX_FINI," \
+        "     to cairoint.h"
+
+# define CAIRO_MUTEX_INIT(mutex) ???
+# define CAIRO_MUTEX_FINI(mutex) ???
+# define CAIRO_MUTEX_NIL_INITIALIZER {}
+
+#else
+
+# define CAIRO_MUTEX_LOCK(name)
+# define CAIRO_MUTEX_UNLOCK(name)
+
+#endif
+
+#ifndef CAIRO_MUTEX_DECLARE
+#define CAIRO_MUTEX_DECLARE(name) extern cairo_mutex_t name;
+#endif
+
+#include "cairo-mutex-list.h"
+
+#undef CAIRO_MUTEX_DECLARE
+#undef CAIRO_MUTEX_EXTERNAL
+
+#ifndef CAIRO_MUTEX_INITIALIZE
+
+#define CAIRO_MUTEX_INITIALIZE() do { \
+    if (!_cairo_mutex_initialized) \
+        _cairo_mutex_initialize(); \
+} while(0)
+
+cairo_private extern cairo_bool_t _cairo_mutex_initialized;
+cairo_private void _cairo_mutex_initialize(void);
+
+#endif
+
+#endif
diff --git a/src/cairo-mutex.c b/src/cairo-mutex.c
new file mode 100644
index 0000000..8b9437e
--- /dev/null
+++ b/src/cairo-mutex.c
@@ -0,0 +1,51 @@
+/* cairo - a vector graphics library with display and print output
+ *
+ * Copyright ? 2007 the cairo graphics library project
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ *
+ * The Original Code is the cairo graphics library.
+ *
+ * Contributor(s):
+ *	Mathias Hasselmann <mathias.hasselmann at gmx.de>
+ */
+
+#define CAIRO_MUTEX_DECLARE(name) cairo_mutex_t name = CAIRO_MUTEX_NIL_INITIALIZER;
+#include "cairo-mutex-private.h"
+
+#if !HAVE_PTHREAD_H
+
+cairo_bool_t _cairo_mutex_initialized = FALSE;
+
+void _cairo_mutex_initialize (void)
+{
+    if (_cairo_mutex_initialized)
+        return;
+
+#define CAIRO_MUTEX_DECLARE(mutex) CAIRO_MUTEX_INIT (mutex);
+#include "cairo-mutex-list.h"
+#undef CAIRO_MUTEX_DECLARE
+}
+
+#endif
diff --git a/src/cairo-os2-surface.c b/src/cairo-os2-surface.c
index f6ec8f6..6ce77fc 100644
--- a/src/cairo-os2-surface.c
+++ b/src/cairo-os2-surface.c
@@ -68,14 +68,6 @@
 /* Initialization counter: */
 static int cairo_os2_initialization_count = 0;
 
-/* The mutex semaphores Cairo uses all around: */
-HMTX _cairo_scaled_font_map_mutex = 0;
-HMTX _global_image_glyph_cache_mutex = 0;
-HMTX _cairo_font_face_mutex = 0;
-#ifdef CAIRO_HAS_FT_FONT
-HMTX _cairo_ft_unscaled_font_map_mutex = 0;
-#endif
-
 static void inline
 DisableFPUException (void)
 {
@@ -103,18 +95,6 @@ cairo_os2_init (void)
 
     DisableFPUException ();
 
-    /* Create the mutex semaphores we'll use! */
-
-    /* cairo-font.c: */
-    DosCreateMutexSem (NULL, &_cairo_scaled_font_map_mutex, 0, FALSE);
-    DosCreateMutexSem (NULL, &_global_image_glyph_cache_mutex, 0, FALSE);
-    DosCreateMutexSem (NULL, &_cairo_font_face_mutex, 0, FALSE);
-
-#ifdef CAIRO_HAS_FT_FONT
-    /* cairo-ft-font.c: */
-    DosCreateMutexSem (NULL, &_cairo_ft_unscaled_font_map_mutex, 0, FALSE);
-#endif
-
     /* Initialize FontConfig */
     FcInit ();
 }
diff --git a/src/cairo-paginated-surface.c b/src/cairo-paginated-surface.c
index c8e4612..c8c9a72 100644
--- a/src/cairo-paginated-surface.c
+++ b/src/cairo-paginated-surface.c
@@ -45,6 +45,7 @@
 #include "cairo-paginated-surface-private.h"
 #include "cairo-meta-surface-private.h"
 #include "cairo-analysis-surface-private.h"
+#include "cairo-mutex-private.h"
 
 typedef struct _cairo_paginated_surface {
     cairo_surface_t base;
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index ad5b348..96b0076 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -29,6 +29,7 @@
  */
 
 #include "cairoint.h"
+#include "cairo-mutex-private.h"
 
 const cairo_solid_pattern_t cairo_pattern_nil = {
     { CAIRO_PATTERN_TYPE_SOLID,         /* type */
@@ -84,6 +85,8 @@ _cairo_pattern_set_error (cairo_pattern_t *pattern,
 static void
 _cairo_pattern_init (cairo_pattern_t *pattern, cairo_pattern_type_t type)
 {
+    CAIRO_MUTEX_INITIALIZE ();
+
     pattern->type      = type;
     pattern->ref_count = 1;
     pattern->status    = CAIRO_STATUS_SUCCESS;
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index f3b126e..dd48b8f 100755
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -37,6 +37,7 @@
  */
 
 #include "cairoint.h"
+#include "cairo-mutex-private.h"
 #include "cairo-scaled-font-test.h"
 
 static cairo_bool_t
@@ -185,8 +186,6 @@ typedef struct _cairo_scaled_font_map {
 
 static cairo_scaled_font_map_t *cairo_scaled_font_map = NULL;
 
-CAIRO_MUTEX_DECLARE (_cairo_scaled_font_map_mutex);
-
 static int
 _cairo_scaled_font_keys_equal (const void *abstract_key_a, const void *abstract_key_b);
 
diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index f134bc2..f4c68a2 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -39,6 +39,7 @@
 
 #include "cairoint.h"
 #include "cairo-surface-fallback-private.h"
+#include "cairo-mutex-private.h"
 #include "cairo-clip-private.h"
 
 #define DEFINE_NIL_SURFACE(status, name)			\
@@ -181,10 +182,10 @@ _cairo_surface_init (cairo_surface_t			*surface,
 		     const cairo_surface_backend_t	*backend,
 		     cairo_content_t			 content)
 {
-    surface->backend = backend;
+    CAIRO_MUTEX_INITIALIZE ();
 
+    surface->backend = backend;
     surface->content = content;
-
     surface->type = backend->type;
 
     surface->ref_count = 1;
diff --git a/src/cairo-win32-font.c b/src/cairo-win32-font.c
index 679d52d..4932d80 100644
--- a/src/cairo-win32-font.c
+++ b/src/cairo-win32-font.c
@@ -239,8 +239,6 @@ _win32_scaled_font_create (LOGFONTW                   *logfont,
     cairo_matrix_t scale;
     cairo_status_t status;
 
-    _cairo_win32_initialize ();
-
     f = malloc (sizeof(cairo_win32_scaled_font_t));
     if (f == NULL)
 	return NULL;
@@ -472,8 +470,6 @@ _cairo_win32_scaled_font_create_toy (cairo_toy_font_face_t *toy_face,
     int face_name_len;
     cairo_status_t status;
 
-    _cairo_win32_initialize ();
-
     status = _cairo_utf8_to_utf16 (toy_face->family, -1,
 				   &face_name, &face_name_len);
     if (status)
@@ -1510,8 +1506,6 @@ _cairo_win32_font_face_scaled_font_create (void			*abstract_face,
 {
     cairo_win32_font_face_t *font_face = abstract_face;
 
-    _cairo_win32_initialize ();
-
     *font = _win32_scaled_font_create (&font_face->logfont,
 				       font_face->hfont,
 				       &font_face->base,
@@ -1549,8 +1543,6 @@ cairo_win32_font_face_create_for_logfontw (LOGFONTW *logfont)
 {
     cairo_win32_font_face_t *font_face;
 
-    _cairo_win32_initialize ();
-
     font_face = malloc (sizeof (cairo_win32_font_face_t));
     if (!font_face) {
 	_cairo_error (CAIRO_STATUS_NO_MEMORY);
@@ -1584,8 +1576,6 @@ cairo_win32_font_face_create_for_hfont (HFONT font)
 {
     cairo_win32_font_face_t *font_face;
 
-    _cairo_win32_initialize ();
-
     font_face = malloc (sizeof (cairo_win32_font_face_t));
     if (!font_face) {
 	_cairo_error (CAIRO_STATUS_NO_MEMORY);
diff --git a/src/cairo-win32-private.h b/src/cairo-win32-private.h
index 220c9d3..08aeafa 100644
--- a/src/cairo-win32-private.h
+++ b/src/cairo-win32-private.h
@@ -105,7 +105,4 @@ _cairo_win32_print_gdi_error (const char *context);
 cairo_bool_t
 _cairo_surface_is_win32 (cairo_surface_t *surface);
 
-void
-_cairo_win32_initialize (void);
-
 #endif /* CAIRO_WIN32_PRIVATE_H */
diff --git a/src/cairo-win32-surface.c b/src/cairo-win32-surface.c
index f0b75d0..4773783 100644
--- a/src/cairo-win32-surface.c
+++ b/src/cairo-win32-surface.c
@@ -327,8 +327,6 @@ _cairo_win32_surface_create_for_dc (HDC             original_dc,
     char *bits;
     int rowstride;
 
-    _cairo_win32_initialize ();
-
     surface = malloc (sizeof (cairo_win32_surface_t));
     if (surface == NULL) {
 	_cairo_error (CAIRO_STATUS_NO_MEMORY);
@@ -1635,8 +1633,6 @@ cairo_win32_surface_create (HDC hdc)
     int depth;
     cairo_format_t format;
 
-    _cairo_win32_initialize ();
-
     /* Try to figure out the drawing bounds for the Device context
      */
     if (GetClipBox (hdc, &rect) == ERROR) {
@@ -1887,76 +1883,6 @@ static const cairo_surface_backend_t cairo_win32_surface_backend = {
     NULL  /* snapshot */
 };
 
-/*
- * 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.
- */
-#if !defined(HAVE_PTHREAD_H) 
-
-CRITICAL_SECTION _cairo_scaled_font_map_mutex;
-#ifdef CAIRO_HAS_FT_FONT
-CRITICAL_SECTION _cairo_ft_unscaled_font_map_mutex;
-#endif
-CRITICAL_SECTION _cairo_font_face_mutex;
-
-static int _cairo_win32_initialized = 0;
-
-void
-_cairo_win32_initialize (void) {
-    if (_cairo_win32_initialized)
-	return;
-
-    /* every 'mutex' from CAIRO_MUTEX_DECALRE needs to be initialized here */
-    InitializeCriticalSection (&_cairo_scaled_font_map_mutex);
-#ifdef CAIRO_HAS_FT_FONT
-    InitializeCriticalSection (&_cairo_ft_unscaled_font_map_mutex);
-#endif
-    InitializeCriticalSection (&_cairo_font_face_mutex);
-
-    _cairo_win32_initialized = 1;
-}
-
-#if !defined(CAIRO_WIN32_STATIC_BUILD)
-
-/*
- * Avoid warning regarding missing prototype
- */
-BOOL WINAPI
-DllMain (HINSTANCE hinstDLL,
-	 DWORD     fdwReason,
-	 LPVOID    lpvReserved);
-
-BOOL WINAPI
-DllMain (HINSTANCE hinstDLL,
-	 DWORD     fdwReason,
-	 LPVOID    lpvReserved)
-{
-  switch (fdwReason)
-  {
-  case DLL_PROCESS_ATTACH:
-    _cairo_win32_initialize();
-    break;
-  case DLL_PROCESS_DETACH:
-    DeleteCriticalSection (&_cairo_scaled_font_map_mutex);
-#ifdef CAIRO_HAS_FT_FONT
-    DeleteCriticalSection (&_cairo_ft_unscaled_font_map_mutex);
-#endif
-    DeleteCriticalSection (&_cairo_font_face_mutex);
-    break;
-  }
-  return TRUE;
-}
-#endif
-#else
-/* Need a function definition here too since it's called outside of ifdefs */
-void
-_cairo_win32_initialize (void)
-{
-}
-#endif
-
 /* Notes:
  *
  * Win32 alpha-understanding functions
diff --git a/src/cairo-xlib-screen.c b/src/cairo-xlib-screen.c
index 2316fe1..29dd2fb 100644
--- a/src/cairo-xlib-screen.c
+++ b/src/cairo-xlib-screen.c
@@ -55,6 +55,7 @@
 #include <string.h>
 
 #include "cairo-xlib-private.h"
+#include "cairo-mutex-private.h"
 
 #include <fontconfig/fontconfig.h>
 
@@ -243,8 +244,6 @@ _cairo_xlib_init_screen_font_options (cairo_xlib_screen_info_t *info)
     cairo_font_options_set_subpixel_order (&info->font_options, subpixel_order);
 }
 
-CAIRO_MUTEX_DECLARE(_xlib_screen_mutex);
-
 static cairo_xlib_screen_info_t *_cairo_xlib_screen_list = NULL;
 
 /* XXX: From this function we should also run through and cleanup
diff --git a/src/cairoint.h b/src/cairoint.h
index e314152..6c81ff8 100755
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -136,81 +136,38 @@ CAIRO_BEGIN_DECLS
 
 #if HAVE_PTHREAD_H
 # include <pthread.h>
-# define CAIRO_MUTEX_DECLARE(name) static pthread_mutex_t name = PTHREAD_MUTEX_INITIALIZER
-# define CAIRO_MUTEX_DECLARE_GLOBAL(name) pthread_mutex_t name = PTHREAD_MUTEX_INITIALIZER
-# define CAIRO_MUTEX_LOCK(name) pthread_mutex_lock (&name)
-# define CAIRO_MUTEX_UNLOCK(name) pthread_mutex_unlock (&name)
-typedef pthread_mutex_t cairo_mutex_t;
-#define CAIRO_MUTEX_INIT(mutex) do {				\
-    pthread_mutex_t tmp_mutex = PTHREAD_MUTEX_INITIALIZER;      \
-    memcpy (mutex, &tmp_mutex, sizeof (tmp_mutex));             \
-} while (0)
-# define CAIRO_MUTEX_FINI(mutex) pthread_mutex_destroy (mutex)
-# define CAIRO_MUTEX_NIL_INITIALIZER PTHREAD_MUTEX_INITIALIZER
-#endif
 
-#if !defined(CAIRO_MUTEX_DECLARE) && defined CAIRO_HAS_WIN32_SURFACE
-# define WIN32_LEAN_AND_MEAN
+  typedef pthread_mutex_t cairo_mutex_t;
+
+#elif defined CAIRO_HAS_WIN32_SURFACE
+
 /* We require Windows 2000 features. Although we don't use them here, things
  * should still work if this header file ends up being the one to include
  * windows.h into a source file, so: */
 # if !defined(WINVER) || (WINVER < 0x0500)
 #  define WINVER 0x0500
 # endif
+
 # if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
 #  define _WIN32_WINNT 0x0500
 # endif
+
+# 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)
-typedef CRITICAL_SECTION cairo_mutex_t;
-# define CAIRO_MUTEX_INIT(mutex) InitializeCriticalSection (mutex)
-# define CAIRO_MUTEX_FINI(mutex) DeleteCriticalSection (mutex)
-# define CAIRO_MUTEX_NIL_INITIALIZER { NULL, 0, 0, NULL, NULL, 0 }
-#endif
 
-#if defined(__OS2__) && !defined(CAIRO_MUTEX_DECLARE)
+  typedef CRITICAL_SECTION cairo_mutex_t;
+
+#elif defined CAIRO_HAS_OS2_SURFACE
 # define INCL_BASE
 # define INCL_PM
 # include <os2.h>
 
-# define CAIRO_MUTEX_DECLARE(name) extern HMTX name
-# define CAIRO_MUTEX_DECLARE_GLOBAL(name) extern HMTX name
-# define CAIRO_MUTEX_LOCK(name) DosRequestMutexSem(name, SEM_INDEFINITE_WAIT)
-# define CAIRO_MUTEX_UNLOCK(name) DosReleaseMutexSem(name)
-typedef HMTX cairo_mutex_t;
-# define CAIRO_MUTEX_INIT(mutex) DosCreateMutexSem (NULL, mutex, 0L, FALSE)
-# define CAIRO_MUTEX_FINI(mutex) DosCloseMutexSem (*(mutex))
-# define CAIRO_MUTEX_NIL_INITIALIZER 0
-#endif
+  typedef HMTX cairo_mutex_t;
 
-#if !defined(CAIRO_MUTEX_DECLARE) && defined CAIRO_HAS_BEOS_SURFACE
-cairo_private void _cairo_beos_lock(void*);
-cairo_private void _cairo_beos_unlock(void*);
-  /* the real initialization takes place in a global constructor */
-# define CAIRO_MUTEX_DECLARE(name) extern void* name;
-# define CAIRO_MUTEX_DECLARE_GLOBAL(name) extern void* name;
-# define CAIRO_MUTEX_LOCK(name) _cairo_beos_lock (&name)
-# define CAIRO_MUTEX_UNLOCK(name) _cairo_beos_unlock (&name)
-# error "XXX: Someone who understands BeOS needs to add definitions for" \
-        "     cairo_mutex_t, CAIRO_MUTEX_INIT, and CAIRO_MUTEX_FINI," \
-        "     to cairoint.h"
-typedef ??? cairo_mutex_t;
-# define CAIRO_MUTEX_INIT(mutex) ???
-# define CAIRO_MUTEX_FINI(mutex) ???
-# define CAIRO_MUTEX_NIL_INITIALIZER {}
-#endif
+#elif defined CAIRO_HAS_BEOS_SURFACE
+
+  typedef void* cairo_mutex_t;
 
-#ifndef CAIRO_MUTEX_DECLARE
-# error "No mutex declarations. Cairo will not work with multiple threads." \
-	"(Remove this #error directive to acknowledge & accept this limitation)."
-# define CAIRO_MUTEX_DECLARE(name)
-# define CAIRO_MUTEX_DECLARE_GLOBAL(name)
-# define CAIRO_MUTEX_LOCK(name)
-# define CAIRO_MUTEX_UNLOCK(name)
 #endif
 
 #undef MIN
-- 
1.4.4.2

-------------- next part --------------
>From b730791ad1c9f666b7cec40052b5674187aea1c9 Mon Sep 17 00:00:00 2001
From: Mathias Hasselmann <mathias.hasselmann at gmx.de>
Date: Mon, 5 Mar 2007 19:49:19 +0100
Subject: [PATCH] [PATCH] Copyright cleanups and mutex finalization on OS/2

---
 src/cairo-mutex-list.h    |    3 +--
 src/cairo-mutex-private.h |    9 +++++++--
 src/cairo-mutex.c         |    2 +-
 src/cairo-os2-surface.c   |   25 +++----------------------
 4 files changed, 12 insertions(+), 27 deletions(-)

diff --git a/src/cairo-mutex-list.h b/src/cairo-mutex-list.h
index 38d305f..c624242 100644
--- a/src/cairo-mutex-list.h
+++ b/src/cairo-mutex-list.h
@@ -1,6 +1,6 @@
 /* cairo - a vector graphics library with display and print output
  *
- * Copyright ? 2007 the cairo graphics library project
+ * Copyright ? 2007 Mathias Hasselmann
  *
  * This library is free software; you can redistribute it and/or
  * modify it either under the terms of the GNU Lesser General Public
@@ -46,7 +46,6 @@ CAIRO_MUTEX_DECLARE (_xlib_screen_mutex);
 #endif
 
 #if CAIRO_HAS_OS2_SURFACE
-CAIRO_MUTEX_DECLARE (cairo_toy_font_face_hash_table_mutex);
 CAIRO_MUTEX_DECLARE (_global_image_glyph_cache_mutex);
 #endif
 
diff --git a/src/cairo-mutex-private.h b/src/cairo-mutex-private.h
index fdaeb8b..41d0049 100644
--- a/src/cairo-mutex-private.h
+++ b/src/cairo-mutex-private.h
@@ -2,7 +2,7 @@
  *
  * Copyright ? 2002 University of Southern California
  * Copyright ? 2005 Red Hat, Inc.
- * Copyright ? 2007 the cairo graphics library project
+ * Copyright ? 2007 Mathias Hasselmann
  *
  * This library is free software; you can redistribute it and/or
  * modify it either under the terms of the GNU Lesser General Public
@@ -67,7 +67,12 @@
 # define CAIRO_MUTEX_LOCK(name) DosRequestMutexSem(name, SEM_INDEFINITE_WAIT)
 # define CAIRO_MUTEX_UNLOCK(name) DosReleaseMutexSem(name)
 # define CAIRO_MUTEX_INIT(mutex) DosCreateMutexSem (NULL, mutex, 0L, FALSE)
-# define CAIRO_MUTEX_FINI(mutex) DosCloseMutexSem (*(mutex))
+# define CAIRO_MUTEX_FINI(mutex) do {				\
+    if (0 != (mutex)) {						\
+        DosCloseMutexSem (*(mutex));				\
+        (mutex) = 0;						\
+    }								\
+} while (0)
 # define CAIRO_MUTEX_NIL_INITIALIZER 0
 
 #elif defined CAIRO_HAS_BEOS_SURFACE
diff --git a/src/cairo-mutex.c b/src/cairo-mutex.c
index 8b9437e..48ec86b 100644
--- a/src/cairo-mutex.c
+++ b/src/cairo-mutex.c
@@ -1,6 +1,6 @@
 /* cairo - a vector graphics library with display and print output
  *
- * Copyright ? 2007 the cairo graphics library project
+ * Copyright ? 2007 Mathias Hasselmann
  *
  * This library is free software; you can redistribute it and/or
  * modify it either under the terms of the GNU Lesser General Public
diff --git a/src/cairo-os2-surface.c b/src/cairo-os2-surface.c
index 6ce77fc..baaef23 100644
--- a/src/cairo-os2-surface.c
+++ b/src/cairo-os2-surface.c
@@ -117,28 +117,9 @@ cairo_os2_fini (void)
     _cairo_ft_font_reset_static_data ();
 #endif
 
-    /* Destroy the mutex semaphores we've created! */
-    /* cairo-font.c: */
-    if (_cairo_scaled_font_map_mutex) {
-        DosCloseMutexSem (_cairo_scaled_font_map_mutex);
-        _cairo_scaled_font_map_mutex = 0;
-    }
-    if (_global_image_glyph_cache_mutex) {
-        DosCloseMutexSem (_global_image_glyph_cache_mutex);
-        _global_image_glyph_cache_mutex = 0;
-    }
-    if (_cairo_font_face_mutex) {
-        DosCloseMutexSem (_cairo_font_face_mutex);
-        _cairo_font_face_mutex = 0;
-    }
-
-#ifdef CAIRO_HAS_FT_FONT
-    /* cairo-ft-font.c: */
-    if (_cairo_ft_unscaled_font_map_mutex) {
-        DosCloseMutexSem (_cairo_ft_unscaled_font_map_mutex);
-        _cairo_ft_unscaled_font_map_mutex = 0;
-    }
-#endif
+#define CAIRO_MUTEX_DECLARE(name) CAIRO_MUTEX_FINI(name)
+#include "cairo-mutext-list.h"
+#undef CAIRO_MUTEX_DECLARE
 
     /* Uninitialize FontConfig */
     FcFini ();
-- 
1.4.4.2



More information about the cairo mailing list