summaryrefslogtreecommitdiff
path: root/src/cairo-mutex-private.h
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2007-05-01 19:45:29 -0400
committerBehdad Esfahbod <behdad@behdad.org>2007-05-01 19:45:29 -0400
commit06cc74d974a99526829df558606174b41b0ee6e1 (patch)
tree02df4eb4cdc2593b0969f481c335a8a02ac6dba0 /src/cairo-mutex-private.h
parente87a25dc7c73a44b0cdfc4ef368736e7f77fb522 (diff)
[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.
Diffstat (limited to 'src/cairo-mutex-private.h')
-rw-r--r--src/cairo-mutex-private.h93
1 files changed, 67 insertions, 26 deletions
diff --git a/src/cairo-mutex-private.h b/src/cairo-mutex-private.h
index ed89ef51b..88e88bb0f 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 */