1 /* cairo - a vector graphics library with display and print output
3 * Copyright © 2002 University of Southern California
4 * Copyright © 2005,2007 Red Hat, Inc.
5 * Copyright © 2007 Mathias Hasselmann
7 * This library is free software; you can redistribute it and/or
8 * modify it either under the terms of the GNU Lesser General Public
9 * License version 2.1 as published by the Free Software Foundation
10 * (the "LGPL") or, at your option, under the terms of the Mozilla
11 * Public License Version 1.1 (the "MPL"). If you do not alter this
12 * notice, a recipient may use your version of this file under either
13 * the MPL or the LGPL.
15 * You should have received a copy of the LGPL along with this library
16 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * You should have received a copy of the MPL along with this library
19 * in the file COPYING-MPL-1.1
21 * The contents of this file are subject to the Mozilla Public License
22 * Version 1.1 (the "License"); you may not use this file except in
23 * compliance with the License. You may obtain a copy of the License at
24 * http://www.mozilla.org/MPL/
26 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
27 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
28 * the specific language governing rights and limitations.
30 * The Original Code is the cairo graphics library.
32 * The Initial Developer of the Original Code is University of Southern
36 * Carl D. Worth <cworth@cworth.org>
37 * Mathias Hasselmann <mathias.hasselmann@gmx.de>
38 * Behdad Esfahbod <behdad@behdad.org>
41 #ifndef CAIRO_MUTEX_TYPE_PRIVATE_H
42 #define CAIRO_MUTEX_TYPE_PRIVATE_H
44 #include "cairo-compiler-private.h"
45 #include "cairo-mutex-impl-private.h"
47 /* Only the following three are mandatory at this point */
48 #ifndef CAIRO_MUTEX_IMPL_LOCK
49 # error "CAIRO_MUTEX_IMPL_LOCK not defined. Check cairo-mutex-impl-private.h."
51 #ifndef CAIRO_MUTEX_IMPL_UNLOCK
52 # error "CAIRO_MUTEX_IMPL_UNLOCK not defined. Check cairo-mutex-impl-private.h."
54 #ifndef CAIRO_MUTEX_IMPL_NIL_INITIALIZER
55 # error "CAIRO_MUTEX_IMPL_NIL_INITIALIZER not defined. Check cairo-mutex-impl-private.h."
59 /* make sure implementations don't fool us: we decide these ourself */
60 #undef _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER
61 #undef _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER
64 #ifdef CAIRO_MUTEX_IMPL_INIT
66 /* If %CAIRO_MUTEX_IMPL_INIT is defined, we may need to initialize all
68 # ifndef CAIRO_MUTEX_IMPL_INITIALIZE
69 # define CAIRO_MUTEX_IMPL_INITIALIZE() do { \
70 if (!_cairo_mutex_initialized) \
71 _cairo_mutex_initialize (); \
74 /* and make sure we implement the above */
75 # define _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER 1
76 # endif /* CAIRO_MUTEX_IMPL_INITIALIZE */
78 #else /* no CAIRO_MUTEX_IMPL_INIT */
80 /* Otherwise we probably don't need to initialize static mutex'es, */
81 # ifndef CAIRO_MUTEX_IMPL_INITIALIZE
82 # define CAIRO_MUTEX_IMPL_INITIALIZE() CAIRO_MUTEX_IMPL_NOOP
83 # endif /* CAIRO_MUTEX_IMPL_INITIALIZE */
85 /* and dynamic ones can be initialized using the static initializer. */
86 # define CAIRO_MUTEX_IMPL_INIT(mutex) do { \
87 cairo_mutex_t _tmp_mutex = CAIRO_MUTEX_IMPL_NIL_INITIALIZER; \
88 memcpy (&(mutex), &_tmp_mutex, sizeof (_tmp_mutex)); \
91 #endif /* CAIRO_MUTEX_IMPL_INIT */
93 #ifdef CAIRO_MUTEX_IMPL_FINI
95 /* If %CAIRO_MUTEX_IMPL_FINI is defined, we may need to finalize all
97 # ifndef CAIRO_MUTEX_IMPL_FINALIZE
98 # define CAIRO_MUTEX_IMPL_FINALIZE() do { \
99 if (_cairo_mutex_initialized) \
100 _cairo_mutex_finalize (); \
103 /* and make sure we implement the above */
104 # define _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER 1
105 # endif /* CAIRO_MUTEX_IMPL_FINALIZE */
107 #else /* no CAIRO_MUTEX_IMPL_FINI */
109 /* Otherwise we probably don't need to finalize static mutex'es, */
110 # ifndef CAIRO_MUTEX_IMPL_FINALIZE
111 # define CAIRO_MUTEX_IMPL_FINALIZE() CAIRO_MUTEX_IMPL_NOOP
112 # endif /* CAIRO_MUTEX_IMPL_FINALIZE */
114 /* neither do the dynamic ones. */
115 # define CAIRO_MUTEX_IMPL_FINI(mutex) CAIRO_MUTEX_IMPL_NOOP1(mutex)
117 #endif /* CAIRO_MUTEX_IMPL_FINI */
120 #ifndef _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER
121 #define _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER 0
123 #ifndef _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER
124 #define _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER 0
128 /* Make sure everything we want is defined */
129 #ifndef CAIRO_MUTEX_IMPL_INITIALIZE
130 # error "CAIRO_MUTEX_IMPL_INITIALIZE not defined"
132 #ifndef CAIRO_MUTEX_IMPL_FINALIZE
133 # error "CAIRO_MUTEX_IMPL_FINALIZE not defined"
135 #ifndef CAIRO_MUTEX_IMPL_LOCK
136 # error "CAIRO_MUTEX_IMPL_LOCK not defined"
138 #ifndef CAIRO_MUTEX_IMPL_UNLOCK
139 # error "CAIRO_MUTEX_IMPL_UNLOCK not defined"
141 #ifndef CAIRO_MUTEX_IMPL_INIT
142 # error "CAIRO_MUTEX_IMPL_INIT not defined"
144 #ifndef CAIRO_MUTEX_IMPL_FINI
145 # error "CAIRO_MUTEX_IMPL_FINI not defined"
147 #ifndef CAIRO_MUTEX_IMPL_NIL_INITIALIZER
148 # error "CAIRO_MUTEX_IMPL_NIL_INITIALIZER not defined"
152 /* Public interface. */
154 /* By default it simply uses the implementation provided.
155 * But we can provide for debugging features by overriding them */
157 #ifndef CAIRO_MUTEX_DEBUG
158 typedef cairo_mutex_impl_t cairo_mutex_t
;
160 # define cairo_mutex_t cairo_mutex_impl_t
163 #define CAIRO_MUTEX_INITIALIZE CAIRO_MUTEX_IMPL_INITIALIZE
164 #define CAIRO_MUTEX_FINALIZE CAIRO_MUTEX_IMPL_FINALIZE
165 #define CAIRO_MUTEX_LOCK CAIRO_MUTEX_IMPL_LOCK
166 #define CAIRO_MUTEX_UNLOCK CAIRO_MUTEX_IMPL_UNLOCK
167 #define CAIRO_MUTEX_INIT CAIRO_MUTEX_IMPL_INIT
168 #define CAIRO_MUTEX_FINI CAIRO_MUTEX_IMPL_FINI
169 #define CAIRO_MUTEX_NIL_INITIALIZER CAIRO_MUTEX_IMPL_NIL_INITIALIZER
171 #ifndef CAIRO_MUTEX_IS_LOCKED
172 # define CAIRO_MUTEX_IS_LOCKED(name) 1
174 #ifndef CAIRO_MUTEX_IS_UNLOCKED
175 # define CAIRO_MUTEX_IS_UNLOCKED(name) 1
179 /* Debugging support */
181 #ifdef CAIRO_MUTEX_DEBUG
183 /* TODO add mutex debugging facilities here (eg deadlock detection) */
185 #endif /* CAIRO_MUTEX_DEBUG */