50
50
#include "cairo-mutex-type-private.h"
52
/* Only the following three are mandatory at this point */
53
#ifndef CAIRO_MUTEX_LOCK
54
# error "CAIRO_MUTEX_LOCK not defined. Check cairo-mutex-type-private.h."
56
#ifndef CAIRO_MUTEX_UNLOCK
57
# error "CAIRO_MUTEX_UNLOCK not defined. Check cairo-mutex-type-private.h."
59
#ifndef CAIRO_MUTEX_NIL_INITIALIZER
60
# error "CAIRO_MUTEX_NIL_INITIALIZER not defined. Check cairo-mutex-type-private.h."
54
#ifndef CAIRO_MUTEX_DECLARE
55
#define CAIRO_MUTEX_DECLARE(name) extern cairo_mutex_t name;
66
#define CAIRO_MUTEX_DECLARE(mutex) extern cairo_mutex_t mutex
57
67
#include "cairo-mutex-list-private.h"
58
68
#undef CAIRO_MUTEX_DECLARE
61
#ifndef CAIRO_MUTEX_INIT
62
# define CAIRO_MUTEX_INIT(_mutex) do { \
63
cairo_mutex_t _tmp_mutex = CAIRO_MUTEX_NIL_INITIALIZER; \
64
memcpy ((_mutex), &_tmp_mutex, sizeof (_tmp_mutex)); \
68
#ifndef CAIRO_MUTEX_FINI
69
# define CAIRO_MUTEX_FINI(mutex) CAIRO_MUTEX_NOOP
73
#ifndef CAIRO_MUTEX_INITIALIZE
74
# define CAIRO_MUTEX_USE_GENERIC_INITIALIZATION 1
76
# undef CAIRO_MUTEX_USE_GENERIC_INITIALIZATION
71
/* make sure implementations don't fool us: we decide these ourself */
72
#undef _CAIRO_MUTEX_USE_STATIC_INITIALIZER
73
#undef _CAIRO_MUTEX_USE_STATIC_FINALIZER
76
#ifdef CAIRO_MUTEX_INIT
78
/* If CAIRO_MUTEX_INIT is defined, we may need to initialize all
80
# ifndef CAIRO_MUTEX_INITIALIZE
81
# define CAIRO_MUTEX_INITIALIZE() do { \
82
if (!_cairo_mutex_initialized) \
83
_cairo_mutex_initialize (); \
86
cairo_private void _cairo_mutex_initialize (void);
88
/* and make sure we implement the above */
89
# define _CAIRO_MUTEX_USE_STATIC_INITIALIZER 1
90
# endif /* CAIRO_MUTEX_INITIALIZE */
92
#else /* no CAIRO_MUTEX_INIT */
94
/* Otherwise we probably don't need to initialize static mutex'es, */
95
# ifndef CAIRO_MUTEX_INITIALIZE
96
# define CAIRO_MUTEX_INITIALIZE() CAIRO_MUTEX_NOOP
97
# endif /* CAIRO_MUTEX_INITIALIZE */
99
/* and dynamic ones can be initialized using the static initializer. */
100
# define CAIRO_MUTEX_INIT(mutex) do { \
101
cairo_mutex_t _tmp_mutex = CAIRO_MUTEX_NIL_INITIALIZER; \
102
memcpy (&(mutex), &_tmp_mutex, sizeof (_tmp_mutex)); \
105
#endif /* CAIRO_MUTEX_INIT */
108
#ifdef CAIRO_MUTEX_FINI
110
/* If CAIRO_MUTEX_FINI is defined, we may need to finalize all
111
* static mutex'es. */
112
# ifndef CAIRO_MUTEX_FINALIZE
113
# define CAIRO_MUTEX_FINALIZE() do { \
114
if (_cairo_mutex_initialized) \
115
_cairo_mutex_finalize (); \
118
cairo_private void _cairo_mutex_finalize (void);
120
/* and make sure we implement the above */
121
# define _CAIRO_MUTEX_USE_STATIC_FINALIZER 1
122
# endif /* CAIRO_MUTEX_FINALIZE */
124
#else /* no CAIRO_MUTEX_FINI */
126
/* Otherwise we probably don't need to finalize static mutex'es, */
77
127
# ifndef CAIRO_MUTEX_FINALIZE
78
128
# define CAIRO_MUTEX_FINALIZE() CAIRO_MUTEX_NOOP
82
#if CAIRO_MUTEX_USE_GENERIC_INITIALIZATION
84
#define CAIRO_MUTEX_INITIALIZE() do { \
85
if (!_cairo_mutex_initialized) \
86
_cairo_mutex_initialize (); \
89
#define CAIRO_MUTEX_FINALIZE() do { \
90
if (_cairo_mutex_initialized) \
91
_cairo_mutex_finalize (); \
94
cairo_private extern cairo_bool_t _cairo_mutex_initialized;
95
cairo_private void _cairo_mutex_initialize(void);
96
cairo_private void _cairo_mutex_finalize(void);
129
# endif /* CAIRO_MUTEX_FINALIZE */
131
/* neither do the dynamic ones. */
132
# define CAIRO_MUTEX_FINI(mutex) CAIRO_MUTEX_NOOP1(mutex)
134
#endif /* CAIRO_MUTEX_FINI */
137
#ifndef _CAIRO_MUTEX_USE_STATIC_INITIALIZER
138
#define _CAIRO_MUTEX_USE_STATIC_INITIALIZER 0
140
#ifndef _CAIRO_MUTEX_USE_STATIC_FINALIZER
141
#define _CAIRO_MUTEX_USE_STATIC_FINALIZER 0
144
/* only if using static initializer and/or finalizer define the boolean */
145
#if _CAIRO_MUTEX_USE_STATIC_INITIALIZER || _CAIRO_MUTEX_USE_STATIC_FINALIZER
146
cairo_private extern cairo_bool_t _cairo_mutex_initialized;