[cairo-commit] 11 commits - RELEASING src/cairo-ft-font.c
src/cairo-mutex.c src/cairo-mutex-private.h
src/cairo-mutex-type-private.h src/cairo-scaled-font.c
Behdad Esfahbod
behdad at kemper.freedesktop.org
Tue May 1 17:10:29 PDT 2007
RELEASING | 2
src/cairo-ft-font.c | 4 -
src/cairo-mutex-private.h | 110 +++++++++++++++++++++++++---------
src/cairo-mutex-type-private.h | 129 +++++++++++++++++++++++++++++++++--------
src/cairo-mutex.c | 29 ++++++---
src/cairo-scaled-font.c | 4 -
6 files changed, 210 insertions(+), 68 deletions(-)
New commits:
diff-tree f3153091b742daffa853f2c31b76aa9689c5165a (from 5bfd6553fd028f1429d72c60d04788de4a3c0d58)
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue May 1 20:10:39 2007 -0400
[cairo-mutex] Document the API for adding cairo_mutex_t implementations
diff --git a/src/cairo-mutex-type-private.h b/src/cairo-mutex-type-private.h
index 2ab1d37..59d581a 100644
--- a/src/cairo-mutex-type-private.h
+++ b/src/cairo-mutex-type-private.h
@@ -56,6 +56,89 @@ CAIRO_BEGIN_DECLS
#define CAIRO_MUTEX_NOOP1(expr) do { if (expr) ; } while (0)
+/* Cairo mutex implementation:
+ *
+ * Any new mutex implementation needs to do the following:
+ *
+ * - Condition on the right header or feature. Headers are
+ * preferred as eg. you still can use win32 mutex implementation
+ * on a win32 system even if you do not compile the win32
+ * surface/backend.
+ *
+ * - typedef cairo_mutex_t to the proper mutex type on your target
+ * system. Note that you may or may not need to use a pointer,
+ * depending on what kinds of initialization your mutex
+ * implementation supports. No trailing semicolon needed.
+ * You should be able to compile the following snippet (don't try
+ * running it):
+ *
+ * cairo_mutex_t _cairo_some_mutex;
+ *
+ * - #define CAIRO_MUTEX_LOCK(mutex) and CAIRO_MUTEX_UNLOCK(mutex) to
+ * proper statement to lock/unlock the mutex object passed in.
+ * You can (and should) assume that the mutex is already
+ * initialized, and is-not-already-locked/is-locked,
+ * respectively. Use the "do { ... } while (0)" idiom if necessary.
+ * No trailing semicolons are needed (in any macro you define here).
+ * You should be able to compile the following snippet:
+ *
+ * cairo_mutex_t _cairo_some_mutex;
+ *
+ * if (1)
+ * CAIRO_MUTEX_LOCK (_cairo_some_mutex);
+ * else
+ * CAIRO_MUTEX_UNLOCK (_cairo_some_mutex);
+ *
+ * - #define CAIRO_MUTEX_NIL_INITIALIZER to something that can
+ * initialize the cairo_mutex_t type you defined. Most of the
+ * time one of 0, NULL, or {} works. At this point
+ * you should be able to compile the following snippet:
+ *
+ * cairo_mutex_t _cairo_some_mutex = CAIRO_MUTEX_NIL_INITIALIZER;
+ *
+ * if (1)
+ * CAIRO_MUTEX_LOCK (_cairo_some_mutex);
+ * else
+ * CAIRO_MUTEX_UNLOCK (_cairo_some_mutex);
+ *
+ * - If the above code is not enough to initialize a mutex on
+ * your platform, #define CAIRO_MUTEX_INIT(mutex) to statement
+ * to initialize the mutex (allocate resources, etc). Such that
+ * you should be able to compile AND RUN the following snippet:
+ *
+ * cairo_mutex_t _cairo_some_mutex = CAIRO_MUTEX_NIL_INITIALIZER;
+ *
+ * CAIRO_MUTEX_INIT (_cairo_some_mutex);
+ *
+ * if (1)
+ * CAIRO_MUTEX_LOCK (_cairo_some_mutex);
+ * else
+ * CAIRO_MUTEX_UNLOCK (_cairo_some_mutex);
+ *
+ * - If you define CAIRO_MUTEX_INIT(mutex), cairo will use it to
+ * initialize all static mutex'es. If for any reason that should
+ * not happen (eg. CAIRO_MUTEX_INIT is just a faster way than
+ * what cairo does using CAIRO_MUTEX_NIL_INITIALIZER), then
+ * #define CAIRO_MUTEX_INITIALIZE() CAIRO_MUTEX_NOOP
+ *
+ * - If your system supports freeing a mutex object (deallocating
+ * resources, etc), then #define CAIRO_MUTEX_FINI(mutex) to do
+ * that.
+ *
+ * - If you define CAIRO_MUTEX_FINI(mutex), cairo will use it to
+ * define a finalizer function to finalize all static mutex'es.
+ * However, it's up to you to call CAIRO_MUTEX_FINALIZE() at
+ * proper places, eg. when the system is unloading the cairo library.
+ * So, if for any reason finalizing static mutex'es is not needed
+ * (eg. you never call CAIRO_MUTEX_FINALIZE), then
+ * #define CAIRO_MUTEX_FINALIZE() CAIRO_MUTEX_NOOP
+ *
+ * - That is all. If for any reason you think the above API is
+ * not enough to implement cairo_mutex_t on your system, please
+ * stop and write to the cairo mailing list about it. DO NOT
+ * poke around cairo-mutex-private.h for possible solutions.
+ */
+
#if CAIRO_NO_MUTEX
/* A poor man's mutex */
diff-tree 5bfd6553fd028f1429d72c60d04788de4a3c0d58 (from c4e0a059feb9c2e0c32966dcb168861e75a244b7)
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue May 1 19:48:33 2007 -0400
[cairo-mutex] Define a NOOP CAIRO_MUTEX_FINALIZE() for pthread
as now the mutex layer will define a generic CAIRO_MUTEX_FINALIZE()
whenever the implementation defines CAIRO_MUTEX_FINI(). In the
case of pthread however we don't need finalization as we don't
have any place to call it, and pthread_mutex_destroy() doesn't
do much anyway.
diff --git a/src/cairo-mutex-type-private.h b/src/cairo-mutex-type-private.h
index 111c0bd..2ab1d37 100644
--- a/src/cairo-mutex-type-private.h
+++ b/src/cairo-mutex-type-private.h
@@ -76,6 +76,7 @@ CAIRO_BEGIN_DECLS
# define CAIRO_MUTEX_LOCK(mutex) pthread_mutex_lock (&(mutex))
# define CAIRO_MUTEX_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
# define CAIRO_MUTEX_FINI(mutex) pthread_mutex_destroy (&(mutex))
+# define CAIRO_MUTEX_FINALIZE() CAIRO_MUTEX_NOOP
# define CAIRO_MUTEX_NIL_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#elif HAVE_WINDOWS_H /*******************************************************/
diff-tree c4e0a059feb9c2e0c32966dcb168861e75a244b7 (from 06cc74d974a99526829df558606174b41b0ee6e1)
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue May 1 19:46:51 2007 -0400
[cairo-mutex] Remove NOOP definition of CAIRO_MUTEX_INITIALIZE
as now the mutex layer will use a NOOP CAIRO_MUTEX_INITIALIZE
by default if the implementation does not define CAIRO_MUTEX_INIT.
diff --git a/src/cairo-mutex-type-private.h b/src/cairo-mutex-type-private.h
index 8ec85cf..111c0bd 100644
--- a/src/cairo-mutex-type-private.h
+++ b/src/cairo-mutex-type-private.h
@@ -73,7 +73,6 @@ CAIRO_BEGIN_DECLS
typedef pthread_mutex_t cairo_mutex_t;
-# define CAIRO_MUTEX_INITIALIZE() CAIRO_MUTEX_NOOP
# define CAIRO_MUTEX_LOCK(mutex) pthread_mutex_lock (&(mutex))
# define CAIRO_MUTEX_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
# define CAIRO_MUTEX_FINI(mutex) pthread_mutex_destroy (&(mutex))
diff-tree 06cc74d974a99526829df558606174b41b0ee6e1 (from e87a25dc7c73a44b0cdfc4ef368736e7f77fb522)
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue May 1 19:45:29 2007 -0400
[cairo-mutex] Rewrite defaults for CAIRO_MUTEX macros not defined by the implementation
to make them better match the design I have in mind, that I will
document in a minute. They are a lot more readable and understandable
now.
diff --git a/src/cairo-mutex-private.h b/src/cairo-mutex-private.h
index ed89ef5..88e88bb 100644
--- a/src/cairo-mutex-private.h
+++ b/src/cairo-mutex-private.h
@@ -62,50 +62,91 @@
CAIRO_BEGIN_DECLS
+
#define CAIRO_MUTEX_DECLARE(mutex) extern cairo_mutex_t mutex
#include "cairo-mutex-list-private.h"
#undef CAIRO_MUTEX_DECLARE
-#ifndef CAIRO_MUTEX_INIT
+/* make sure implementations don't fool us: we decide these ourself */
+#undef _CAIRO_MUTEX_USE_STATIC_INITIALIZER
+#undef _CAIRO_MUTEX_USE_STATIC_FINALIZER
+
+
+#ifdef CAIRO_MUTEX_INIT
+
+/* If CAIRO_MUTEX_INIT is defined, we may need to initialize all
+ * static mutex'es. */
+# ifndef CAIRO_MUTEX_INITIALIZE
+# define CAIRO_MUTEX_INITIALIZE() do { \
+ if (!_cairo_mutex_initialized) \
+ _cairo_mutex_initialize (); \
+ } while(0)
+
+ cairo_private void _cairo_mutex_initialize (void);
+
+ /* and make sure we implement the above */
+# define _CAIRO_MUTEX_USE_STATIC_INITIALIZER 1
+# endif /* CAIRO_MUTEX_INITIALIZE */
+
+#else /* no CAIRO_MUTEX_INIT */
+
+/* Otherwise we probably don't need to initialize static mutex'es, */
+# ifndef CAIRO_MUTEX_INITIALIZE
+# define CAIRO_MUTEX_INITIALIZE() CAIRO_MUTEX_NOOP
+# endif /* CAIRO_MUTEX_INITIALIZE */
+
+/* and dynamic ones can be initialized using the static initializer. */
# define CAIRO_MUTEX_INIT(mutex) do { \
- cairo_mutex_t _tmp_mutex = CAIRO_MUTEX_NIL_INITIALIZER; \
- memcpy (&(mutex), &_tmp_mutex, sizeof (_tmp_mutex)); \
-} while (0)
-#endif
+ cairo_mutex_t _tmp_mutex = CAIRO_MUTEX_NIL_INITIALIZER; \
+ memcpy (&(mutex), &_tmp_mutex, sizeof (_tmp_mutex)); \
+ } while (0)
-#ifndef CAIRO_MUTEX_FINI
-# define CAIRO_MUTEX_FINI(mutex) CAIRO_MUTEX_NOOP1(mutex)
-#endif
+#endif /* CAIRO_MUTEX_INIT */
-#ifndef CAIRO_MUTEX_INITIALIZE
-# define CAIRO_MUTEX_USE_GENERIC_INITIALIZATION 1
-#else
-# undef CAIRO_MUTEX_USE_GENERIC_INITIALIZATION
+#ifdef CAIRO_MUTEX_FINI
+
+/* If CAIRO_MUTEX_FINI is defined, we may need to finalize all
+ * static mutex'es. */
+# ifndef CAIRO_MUTEX_FINALIZE
+# define CAIRO_MUTEX_FINALIZE() do { \
+ if (_cairo_mutex_initialized) \
+ _cairo_mutex_finalize (); \
+ } while(0)
+
+ cairo_private void _cairo_mutex_finalize (void);
+
+ /* and make sure we implement the above */
+# define _CAIRO_MUTEX_USE_STATIC_FINALIZER 1
+# endif /* CAIRO_MUTEX_FINALIZE */
+
+#else /* no CAIRO_MUTEX_FINI */
+
+/* Otherwise we probably don't need to finalize static mutex'es, */
# ifndef CAIRO_MUTEX_FINALIZE
# define CAIRO_MUTEX_FINALIZE() CAIRO_MUTEX_NOOP
-# endif
-#endif
+# endif /* CAIRO_MUTEX_FINALIZE */
-#if CAIRO_MUTEX_USE_GENERIC_INITIALIZATION
+/* neither do the dynamic ones. */
+# define CAIRO_MUTEX_FINI(mutex) CAIRO_MUTEX_NOOP1(mutex)
-#define CAIRO_MUTEX_INITIALIZE() do { \
- if (!_cairo_mutex_initialized) \
- _cairo_mutex_initialize (); \
-} while(0)
+#endif /* CAIRO_MUTEX_FINI */
-#define CAIRO_MUTEX_FINALIZE() do { \
- if (_cairo_mutex_initialized) \
- _cairo_mutex_finalize (); \
-} while(0)
-cairo_private extern cairo_bool_t _cairo_mutex_initialized;
-cairo_private void _cairo_mutex_initialize(void);
-cairo_private void _cairo_mutex_finalize(void);
+#ifndef _CAIRO_MUTEX_USE_STATIC_INITIALIZER
+#define _CAIRO_MUTEX_USE_STATIC_INITIALIZER 0
+#endif
+#ifndef _CAIRO_MUTEX_USE_STATIC_FINALIZER
+#define _CAIRO_MUTEX_USE_STATIC_FINALIZER 0
+#endif
+/* only if using static initializer and/or finalizer define the boolean */
+#if _CAIRO_MUTEX_USE_STATIC_INITIALIZER || _CAIRO_MUTEX_USE_STATIC_FINALIZER
+ cairo_private extern cairo_bool_t _cairo_mutex_initialized;
#endif
+
CAIRO_END_DECLS
/* Make sure everything we want is defined */
diff --git a/src/cairo-mutex.c b/src/cairo-mutex.c
index 3256441..a2ac7cb 100644
--- a/src/cairo-mutex.c
+++ b/src/cairo-mutex.c
@@ -37,10 +37,21 @@
#include "cairo-mutex-list-private.h"
#undef CAIRO_MUTEX_DECLARE
-#if CAIRO_MUTEX_USE_GENERIC_INITIALIZATION
+#if _CAIRO_MUTEX_USE_STATIC_INITIALIZER || _CAIRO_MUTEX_USE_STATIC_FINALIZER
-cairo_bool_t _cairo_mutex_initialized = FALSE;
+# if _CAIRO_MUTEX_USE_STATIC_INITIALIZER
+# define _CAIRO_MUTEX_INITALIZED_DEFAULT_VALUE FALSE
+# else
+# define _CAIRO_MUTEX_INITALIZED_DEFAULT_VALUE TRUE
+# endif
+cairo_bool_t _cairo_mutex_initialized = _CAIRO_MUTEX_INITALIZED_DEFAULT_VALUE;
+
+# undef _CAIRO_MUTEX_INITALIZED_DEFAULT_VALUE
+
+#endif
+
+#if _CAIRO_MUTEX_USE_STATIC_INITIALIZER
void _cairo_mutex_initialize (void)
{
if (_cairo_mutex_initialized)
@@ -52,7 +63,9 @@ void _cairo_mutex_initialize (void)
#include "cairo-mutex-list-private.h"
#undef CAIRO_MUTEX_DECLARE
}
+#endif
+#if _CAIRO_MUTEX_USE_STATIC_FINALIZER
void _cairo_mutex_finalize (void)
{
if (!_cairo_mutex_initialized)
@@ -64,5 +77,4 @@ void _cairo_mutex_finalize (void)
#include "cairo-mutex-list-private.h"
#undef CAIRO_MUTEX_DECLARE
}
-
#endif
diff-tree e87a25dc7c73a44b0cdfc4ef368736e7f77fb522 (from 1a33e44aa5d73f568c4164c41f9595964e9f1bbb)
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue May 1 19:24:26 2007 -0400
[cairo-mutex] Fix usage of CAIRO_MUTEX_DECLARE()
Previously cairo-mutex.c was abusing cairo-mutex-private.h by
defining CAIRO_MUTEX_DECLARE before including it, and
cairo-mutex-private.h was simply not overriding any available
CAIRO_MUTEX_DECLARE. This is not the way it should be.
cairo-mutex.c should instead define CAIRO_MUTEX_DECLARE and
include cairo-mutex-list-private.h for itself.
diff --git a/src/cairo-mutex-private.h b/src/cairo-mutex-private.h
index 9e058ff..ed89ef5 100644
--- a/src/cairo-mutex-private.h
+++ b/src/cairo-mutex-private.h
@@ -62,9 +62,7 @@
CAIRO_BEGIN_DECLS
-#ifndef CAIRO_MUTEX_DECLARE
-#define CAIRO_MUTEX_DECLARE(mutex) extern cairo_mutex_t mutex;
-#endif
+#define CAIRO_MUTEX_DECLARE(mutex) extern cairo_mutex_t mutex
#include "cairo-mutex-list-private.h"
#undef CAIRO_MUTEX_DECLARE
diff --git a/src/cairo-mutex.c b/src/cairo-mutex.c
index df21af3..3256441 100644
--- a/src/cairo-mutex.c
+++ b/src/cairo-mutex.c
@@ -31,11 +31,12 @@
* Mathias Hasselmann <mathias.hasselmann at gmx.de>
*/
-#define CAIRO_MUTEX_DECLARE(mutex) \
- cairo_mutex_t mutex = CAIRO_MUTEX_NIL_INITIALIZER;
-
#include "cairoint.h"
+#define CAIRO_MUTEX_DECLARE(mutex) cairo_mutex_t mutex = CAIRO_MUTEX_NIL_INITIALIZER
+#include "cairo-mutex-list-private.h"
+#undef CAIRO_MUTEX_DECLARE
+
#if CAIRO_MUTEX_USE_GENERIC_INITIALIZATION
cairo_bool_t _cairo_mutex_initialized = FALSE;
@@ -47,7 +48,7 @@ void _cairo_mutex_initialize (void)
_cairo_mutex_initialized = TRUE;
-#define CAIRO_MUTEX_DECLARE(mutex) CAIRO_MUTEX_INIT (mutex);
+#define CAIRO_MUTEX_DECLARE(mutex) CAIRO_MUTEX_INIT (mutex)
#include "cairo-mutex-list-private.h"
#undef CAIRO_MUTEX_DECLARE
}
diff-tree 1a33e44aa5d73f568c4164c41f9595964e9f1bbb (from 4764e6222bf4d5223fc2fbb139bb31a24819b2b5)
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue May 1 18:13:19 2007 -0400
[RELEASING] Update GNOME URL to point to 2.19 planning page
diff --git a/RELEASING b/RELEASING
index 0573b1e..a568153 100644
--- a/RELEASING
+++ b/RELEASING
@@ -120,4 +120,4 @@ Here are the steps to follow to create a
or update the ExternalDependencies page for the current cycle if you
know where it is. Currently it's:
- http://live.gnome.org/TwoPointSeventeen/ExternalDependencies
+ http://live.gnome.org/TwoPointNineteen/ExternalDependencies
diff-tree 4764e6222bf4d5223fc2fbb139bb31a24819b2b5 (from b5f015f21f3c800919a85f03a081a3ec1648a794)
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue May 1 00:50:03 2007 -0400
[cairo-mutex] Improve error message if no thread implementation found
to put back Carl's "acknowledge and accept" clause (!) before suggesting
use of CAIRO_NO_MUTEX.
diff --git a/src/cairo-mutex-type-private.h b/src/cairo-mutex-type-private.h
index d3c27c1..8ec85cf 100644
--- a/src/cairo-mutex-type-private.h
+++ b/src/cairo-mutex-type-private.h
@@ -117,8 +117,8 @@ CAIRO_BEGIN_DECLS
#else /**********************************************************************/
-# error "XXX: No mutex implementation found. Define CAIRO_NO_MUTEX to 1" \
- " to compile cairo without thread-safety support."
+# error "XXX: No mutex implementation found. Cairo will not work with multiple threads. Define CAIRO_NO_MUTEX to 1 to acknowledge and accept this limitation and compile cairo without thread-safety support."
+
#endif
diff-tree b5f015f21f3c800919a85f03a081a3ec1648a794 (from b0a0a1779dc5cc16423473b6d80ee5099793a47f)
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue May 1 00:48:33 2007 -0400
[cairo-mutex] Make sure mutex implementation declares enough macros
We have defaults for the rest.
diff --git a/src/cairo-mutex-private.h b/src/cairo-mutex-private.h
index c0a8a37..9e058ff 100644
--- a/src/cairo-mutex-private.h
+++ b/src/cairo-mutex-private.h
@@ -49,6 +49,17 @@
#include "cairo-mutex-type-private.h"
+/* Only the following three are mandatory at this point */
+#ifndef CAIRO_MUTEX_LOCK
+# error "CAIRO_MUTEX_LOCK not defined. Check cairo-mutex-type-private.h."
+#endif
+#ifndef CAIRO_MUTEX_UNLOCK
+# error "CAIRO_MUTEX_UNLOCK not defined. Check cairo-mutex-type-private.h."
+#endif
+#ifndef CAIRO_MUTEX_NIL_INITIALIZER
+# error "CAIRO_MUTEX_NIL_INITIALIZER not defined. Check cairo-mutex-type-private.h."
+#endif
+
CAIRO_BEGIN_DECLS
#ifndef CAIRO_MUTEX_DECLARE
diff-tree b0a0a1779dc5cc16423473b6d80ee5099793a47f (from f9154f7eda4272ff99cc8a894082cc5aa1b008ef)
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue May 1 00:47:02 2007 -0400
[cairo-mutex] Make CAIRO_MUTEX_INIT/FINI take mutex object, not pointer to it
This is more consistent with CAIRO_MUTEX_LOCK/UNLOCK.
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index fa18ffd..8be1cae 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -334,7 +334,7 @@ _cairo_ft_unscaled_font_init (cairo_ft_u
}
unscaled->have_scale = FALSE;
- CAIRO_MUTEX_INIT (&unscaled->mutex);
+ CAIRO_MUTEX_INIT (unscaled->mutex);
unscaled->lock_count = 0;
unscaled->faces = NULL;
@@ -369,7 +369,7 @@ _cairo_ft_unscaled_font_fini (cairo_ft_u
unscaled->filename = NULL;
}
- CAIRO_MUTEX_FINI (&unscaled->mutex);
+ CAIRO_MUTEX_FINI (unscaled->mutex);
}
static int
diff --git a/src/cairo-mutex-private.h b/src/cairo-mutex-private.h
index 7979063..c0a8a37 100644
--- a/src/cairo-mutex-private.h
+++ b/src/cairo-mutex-private.h
@@ -61,7 +61,7 @@ CAIRO_BEGIN_DECLS
#ifndef CAIRO_MUTEX_INIT
# define CAIRO_MUTEX_INIT(mutex) do { \
cairo_mutex_t _tmp_mutex = CAIRO_MUTEX_NIL_INITIALIZER; \
- memcpy ((mutex), &_tmp_mutex, sizeof (_tmp_mutex)); \
+ memcpy (&(mutex), &_tmp_mutex, sizeof (_tmp_mutex)); \
} while (0)
#endif
diff --git a/src/cairo-mutex-type-private.h b/src/cairo-mutex-type-private.h
index a98af28..d3c27c1 100644
--- a/src/cairo-mutex-type-private.h
+++ b/src/cairo-mutex-type-private.h
@@ -76,7 +76,7 @@ CAIRO_BEGIN_DECLS
# define CAIRO_MUTEX_INITIALIZE() CAIRO_MUTEX_NOOP
# define CAIRO_MUTEX_LOCK(mutex) pthread_mutex_lock (&(mutex))
# define CAIRO_MUTEX_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
-# define CAIRO_MUTEX_FINI(mutex) pthread_mutex_destroy (mutex)
+# define CAIRO_MUTEX_FINI(mutex) pthread_mutex_destroy (&(mutex))
# define CAIRO_MUTEX_NIL_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#elif HAVE_WINDOWS_H /*******************************************************/
@@ -87,8 +87,8 @@ CAIRO_BEGIN_DECLS
# define CAIRO_MUTEX_LOCK(mutex) EnterCriticalSection (&(mutex))
# define CAIRO_MUTEX_UNLOCK(mutex) LeaveCriticalSection (&(mutex))
-# define CAIRO_MUTEX_INIT(mutex) InitializeCriticalSection (mutex)
-# define CAIRO_MUTEX_FINI(mutex) DeleteCriticalSection (mutex)
+# 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__ /******************************************************/
@@ -101,13 +101,8 @@ CAIRO_BEGIN_DECLS
# define CAIRO_MUTEX_LOCK(mutex) DosRequestMutexSem(mutex, SEM_INDEFINITE_WAIT)
# define CAIRO_MUTEX_UNLOCK(mutex) DosReleaseMutexSem(mutex)
-# define CAIRO_MUTEX_INIT(mutex) DosCreateMutexSem (NULL, mutex, 0L, FALSE)
-# define CAIRO_MUTEX_FINI(mutex) do { \
- if (0 != (mutex)) { \
- DosCloseMutexSem (*(mutex)); \
- (*(mutex)) = 0; \
- } \
-} while (0)
+# define CAIRO_MUTEX_INIT(mutex) DosCreateMutexSem (NULL, &(mutex), 0L, FALSE)
+# define CAIRO_MUTEX_FINI(mutex) DosCloseMutexSem (mutex)
# define CAIRO_MUTEX_NIL_INITIALIZER 0
#elif CAIRO_HAS_BEOS_SURFACE /***********************************************/
@@ -116,8 +111,8 @@ CAIRO_BEGIN_DECLS
# define CAIRO_MUTEX_LOCK(mutex) (mutex)->Lock()
# define CAIRO_MUTEX_UNLOCK(mutex) (mutex)->Unlock()
-# define CAIRO_MUTEX_INIT(mutex) (*(mutex)) = new BLocker()
-# define CAIRO_MUTEX_FINI(mutex) delete (*(mutex))
+# define CAIRO_MUTEX_INIT(mutex) (mutex) = new BLocker()
+# define CAIRO_MUTEX_FINI(mutex) delete (mutex)
# define CAIRO_MUTEX_NIL_INITIALIZER NULL
#else /**********************************************************************/
diff --git a/src/cairo-mutex.c b/src/cairo-mutex.c
index dbdfc5c..df21af3 100644
--- a/src/cairo-mutex.c
+++ b/src/cairo-mutex.c
@@ -47,7 +47,7 @@ void _cairo_mutex_initialize (void)
_cairo_mutex_initialized = TRUE;
-#define CAIRO_MUTEX_DECLARE(mutex) CAIRO_MUTEX_INIT (&mutex);
+#define CAIRO_MUTEX_DECLARE(mutex) CAIRO_MUTEX_INIT (mutex);
#include "cairo-mutex-list-private.h"
#undef CAIRO_MUTEX_DECLARE
}
@@ -59,7 +59,7 @@ void _cairo_mutex_finalize (void)
_cairo_mutex_initialized = FALSE;
-#define CAIRO_MUTEX_DECLARE(mutex) CAIRO_MUTEX_FINI (&mutex)
+#define CAIRO_MUTEX_DECLARE(mutex) CAIRO_MUTEX_FINI (mutex)
#include "cairo-mutex-list-private.h"
#undef CAIRO_MUTEX_DECLARE
}
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index e3ad070..1e05563 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -374,7 +374,7 @@ _cairo_scaled_font_init (cairo_scaled_fo
cairo_font_face_reference (font_face);
- CAIRO_MUTEX_INIT (&scaled_font->mutex);
+ CAIRO_MUTEX_INIT (scaled_font->mutex);
scaled_font->surface_backend = NULL;
scaled_font->surface_private = NULL;
@@ -436,7 +436,7 @@ _cairo_scaled_font_fini (cairo_scaled_fo
if (scaled_font->glyphs != NULL)
_cairo_cache_destroy (scaled_font->glyphs);
- CAIRO_MUTEX_FINI (&scaled_font->mutex);
+ CAIRO_MUTEX_FINI (scaled_font->mutex);
if (scaled_font->surface_backend != NULL &&
scaled_font->surface_backend->scaled_font_fini != NULL)
diff-tree f9154f7eda4272ff99cc8a894082cc5aa1b008ef (from a8d47d0c001a36ddd6c9f09247e6eada408edb24)
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue May 1 00:44:42 2007 -0400
[cairo-mutex] Make sure CAIRO_MUTEX_FINI() evaluates its argument once
diff --git a/src/cairo-mutex-private.h b/src/cairo-mutex-private.h
index 89092e5..7979063 100644
--- a/src/cairo-mutex-private.h
+++ b/src/cairo-mutex-private.h
@@ -66,7 +66,7 @@ CAIRO_BEGIN_DECLS
#endif
#ifndef CAIRO_MUTEX_FINI
-# define CAIRO_MUTEX_FINI(mutex) CAIRO_MUTEX_NOOP
+# define CAIRO_MUTEX_FINI(mutex) CAIRO_MUTEX_NOOP1(mutex)
#endif
diff --git a/src/cairo-mutex-type-private.h b/src/cairo-mutex-type-private.h
index 34b7897..a98af28 100644
--- a/src/cairo-mutex-type-private.h
+++ b/src/cairo-mutex-type-private.h
@@ -52,7 +52,8 @@ CAIRO_BEGIN_DECLS
/* A fully qualified no-operation statement */
#define CAIRO_MUTEX_NOOP do {/*no-op*/} while (0)
-
+/* And one that evaluates it's argument once */
+#define CAIRO_MUTEX_NOOP1(expr) do { if (expr) ; } while (0)
#if CAIRO_NO_MUTEX
diff-tree a8d47d0c001a36ddd6c9f09247e6eada408edb24 (from f57a536fceec73435bb13c44275717792b9b3a8c)
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Tue May 1 00:43:15 2007 -0400
[cairo-mutex] Rename macro arguments from "name" to "mutex"
diff --git a/src/cairo-mutex-private.h b/src/cairo-mutex-private.h
index 67a52b8..89092e5 100644
--- a/src/cairo-mutex-private.h
+++ b/src/cairo-mutex-private.h
@@ -52,16 +52,16 @@
CAIRO_BEGIN_DECLS
#ifndef CAIRO_MUTEX_DECLARE
-#define CAIRO_MUTEX_DECLARE(name) extern cairo_mutex_t name;
+#define CAIRO_MUTEX_DECLARE(mutex) extern cairo_mutex_t mutex;
#endif
#include "cairo-mutex-list-private.h"
#undef CAIRO_MUTEX_DECLARE
#ifndef CAIRO_MUTEX_INIT
-# define CAIRO_MUTEX_INIT(_mutex) do { \
+# define CAIRO_MUTEX_INIT(mutex) do { \
cairo_mutex_t _tmp_mutex = CAIRO_MUTEX_NIL_INITIALIZER; \
- memcpy ((_mutex), &_tmp_mutex, sizeof (_tmp_mutex)); \
+ memcpy ((mutex), &_tmp_mutex, sizeof (_tmp_mutex)); \
} while (0)
#endif
diff --git a/src/cairo-mutex-type-private.h b/src/cairo-mutex-type-private.h
index 0481c22..34b7897 100644
--- a/src/cairo-mutex-type-private.h
+++ b/src/cairo-mutex-type-private.h
@@ -62,8 +62,8 @@ CAIRO_BEGIN_DECLS
typedef int cairo_mutex_t;
# define CAIRO_MUTEX_INITIALIZE() CAIRO_MUTEX_NOOP
-# define CAIRO_MUTEX_LOCK(name) do { while (name) ; (name) = 1; } while (0)
-# define CAIRO_MUTEX_UNLOCK(name) (name) = 0
+# define CAIRO_MUTEX_LOCK(mutex) do { while (mutex) ; (mutex) = 1; } while (0)
+# define CAIRO_MUTEX_UNLOCK(mutex) (mutex) = 0
# define CAIRO_MUTEX_NIL_INITIALIZER 0
#elif HAVE_PTHREAD_H /*******************************************************/
@@ -73,8 +73,8 @@ CAIRO_BEGIN_DECLS
typedef pthread_mutex_t cairo_mutex_t;
# define CAIRO_MUTEX_INITIALIZE() CAIRO_MUTEX_NOOP
-# define CAIRO_MUTEX_LOCK(name) pthread_mutex_lock (&(name))
-# define CAIRO_MUTEX_UNLOCK(name) pthread_mutex_unlock (&(name))
+# define CAIRO_MUTEX_LOCK(mutex) pthread_mutex_lock (&(mutex))
+# define CAIRO_MUTEX_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
# define CAIRO_MUTEX_FINI(mutex) pthread_mutex_destroy (mutex)
# define CAIRO_MUTEX_NIL_INITIALIZER PTHREAD_MUTEX_INITIALIZER
@@ -84,8 +84,8 @@ CAIRO_BEGIN_DECLS
typedef CRITICAL_SECTION cairo_mutex_t;
-# define CAIRO_MUTEX_LOCK(name) EnterCriticalSection (&(name))
-# define CAIRO_MUTEX_UNLOCK(name) LeaveCriticalSection (&(name))
+# define CAIRO_MUTEX_LOCK(mutex) EnterCriticalSection (&(mutex))
+# define CAIRO_MUTEX_UNLOCK(mutex) LeaveCriticalSection (&(mutex))
# 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 }
@@ -98,8 +98,8 @@ CAIRO_BEGIN_DECLS
typedef HMTX cairo_mutex_t;
-# define CAIRO_MUTEX_LOCK(name) DosRequestMutexSem(name, SEM_INDEFINITE_WAIT)
-# define CAIRO_MUTEX_UNLOCK(name) DosReleaseMutexSem(name)
+# define CAIRO_MUTEX_LOCK(mutex) DosRequestMutexSem(mutex, SEM_INDEFINITE_WAIT)
+# define CAIRO_MUTEX_UNLOCK(mutex) DosReleaseMutexSem(mutex)
# define CAIRO_MUTEX_INIT(mutex) DosCreateMutexSem (NULL, mutex, 0L, FALSE)
# define CAIRO_MUTEX_FINI(mutex) do { \
if (0 != (mutex)) { \
@@ -113,8 +113,8 @@ CAIRO_BEGIN_DECLS
typedef BLocker* cairo_mutex_t;
-# define CAIRO_MUTEX_LOCK(name) (name)->Lock()
-# define CAIRO_MUTEX_UNLOCK(name) (name)->Unlock()
+# define CAIRO_MUTEX_LOCK(mutex) (mutex)->Lock()
+# define CAIRO_MUTEX_UNLOCK(mutex) (mutex)->Unlock()
# define CAIRO_MUTEX_INIT(mutex) (*(mutex)) = new BLocker()
# define CAIRO_MUTEX_FINI(mutex) delete (*(mutex))
# define CAIRO_MUTEX_NIL_INITIALIZER NULL
diff --git a/src/cairo-mutex.c b/src/cairo-mutex.c
index 69f4e50..dbdfc5c 100644
--- a/src/cairo-mutex.c
+++ b/src/cairo-mutex.c
@@ -31,8 +31,8 @@
* Mathias Hasselmann <mathias.hasselmann at gmx.de>
*/
-#define CAIRO_MUTEX_DECLARE(name) \
- cairo_mutex_t name = CAIRO_MUTEX_NIL_INITIALIZER;
+#define CAIRO_MUTEX_DECLARE(mutex) \
+ cairo_mutex_t mutex = CAIRO_MUTEX_NIL_INITIALIZER;
#include "cairoint.h"
More information about the cairo-commit
mailing list