Rev 14952 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
14952 | fschmid | 1 | /* cairo - a vector graphics library with display and print output |
2 | * |
||
3 | * Copyright © 2002 University of Southern California |
||
4 | * Copyright © 2005,2007 Red Hat, Inc. |
||
5 | * Copyright © 2007 Mathias Hasselmann |
||
6 | * |
||
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. |
||
14 | * |
||
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 |
||
18122 | mrdocs | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
14952 | fschmid | 18 | * You should have received a copy of the MPL along with this library |
19 | * in the file COPYING-MPL-1.1 |
||
20 | * |
||
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/ |
||
25 | * |
||
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. |
||
29 | * |
||
30 | * The Original Code is the cairo graphics library. |
||
31 | * |
||
32 | * The Initial Developer of the Original Code is University of Southern |
||
33 | * California. |
||
34 | * |
||
35 | * Contributor(s): |
||
36 | * Carl D. Worth <cworth@cworth.org> |
||
37 | * Mathias Hasselmann <mathias.hasselmann@gmx.de> |
||
38 | * Behdad Esfahbod <behdad@behdad.org> |
||
39 | */ |
||
40 | |||
41 | #ifndef CAIRO_MUTEX_TYPE_PRIVATE_H |
||
42 | #define CAIRO_MUTEX_TYPE_PRIVATE_H |
||
43 | |||
44 | #include "cairo-compiler-private.h" |
||
45 | #include "cairo-mutex-impl-private.h" |
||
46 | |||
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." |
||
50 | #endif |
||
51 | #ifndef CAIRO_MUTEX_IMPL_UNLOCK |
||
52 | # error "CAIRO_MUTEX_IMPL_UNLOCK not defined. Check cairo-mutex-impl-private.h." |
||
53 | #endif |
||
54 | #ifndef CAIRO_MUTEX_IMPL_NIL_INITIALIZER |
||
55 | # error "CAIRO_MUTEX_IMPL_NIL_INITIALIZER not defined. Check cairo-mutex-impl-private.h." |
||
56 | #endif |
||
57 | |||
58 | |||
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 |
||
62 | |||
63 | |||
64 | #ifdef CAIRO_MUTEX_IMPL_INIT |
||
65 | |||
66 | /* If %CAIRO_MUTEX_IMPL_INIT is defined, we may need to initialize all |
||
67 | * static mutex'es. */ |
||
68 | # ifndef CAIRO_MUTEX_IMPL_INITIALIZE |
||
69 | # define CAIRO_MUTEX_IMPL_INITIALIZE() do { \ |
||
70 | if (!_cairo_mutex_initialized) \ |
||
71 | _cairo_mutex_initialize (); \ |
||
72 | } while(0) |
||
73 | |||
74 | /* and make sure we implement the above */ |
||
75 | # define _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER 1 |
||
76 | # endif /* CAIRO_MUTEX_IMPL_INITIALIZE */ |
||
77 | |||
78 | #else /* no CAIRO_MUTEX_IMPL_INIT */ |
||
79 | |||
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 */ |
||
84 | |||
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)); \ |
||
89 | } while (0) |
||
90 | |||
91 | #endif /* CAIRO_MUTEX_IMPL_INIT */ |
||
92 | |||
93 | #ifdef CAIRO_MUTEX_IMPL_FINI |
||
94 | |||
95 | /* If %CAIRO_MUTEX_IMPL_FINI is defined, we may need to finalize all |
||
96 | * static mutex'es. */ |
||
97 | # ifndef CAIRO_MUTEX_IMPL_FINALIZE |
||
98 | # define CAIRO_MUTEX_IMPL_FINALIZE() do { \ |
||
99 | if (_cairo_mutex_initialized) \ |
||
100 | _cairo_mutex_finalize (); \ |
||
101 | } while(0) |
||
102 | |||
103 | /* and make sure we implement the above */ |
||
104 | # define _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER 1 |
||
105 | # endif /* CAIRO_MUTEX_IMPL_FINALIZE */ |
||
106 | |||
107 | #else /* no CAIRO_MUTEX_IMPL_FINI */ |
||
108 | |||
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 */ |
||
113 | |||
114 | /* neither do the dynamic ones. */ |
||
115 | # define CAIRO_MUTEX_IMPL_FINI(mutex) CAIRO_MUTEX_IMPL_NOOP1(mutex) |
||
116 | |||
117 | #endif /* CAIRO_MUTEX_IMPL_FINI */ |
||
118 | |||
119 | |||
120 | #ifndef _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER |
||
121 | #define _CAIRO_MUTEX_IMPL_USE_STATIC_INITIALIZER 0 |
||
122 | #endif |
||
123 | #ifndef _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER |
||
124 | #define _CAIRO_MUTEX_IMPL_USE_STATIC_FINALIZER 0 |
||
125 | #endif |
||
126 | |||
127 | |||
128 | /* Make sure everything we want is defined */ |
||
129 | #ifndef CAIRO_MUTEX_IMPL_INITIALIZE |
||
130 | # error "CAIRO_MUTEX_IMPL_INITIALIZE not defined" |
||
131 | #endif |
||
132 | #ifndef CAIRO_MUTEX_IMPL_FINALIZE |
||
133 | # error "CAIRO_MUTEX_IMPL_FINALIZE not defined" |
||
134 | #endif |
||
135 | #ifndef CAIRO_MUTEX_IMPL_LOCK |
||
136 | # error "CAIRO_MUTEX_IMPL_LOCK not defined" |
||
137 | #endif |
||
138 | #ifndef CAIRO_MUTEX_IMPL_UNLOCK |
||
139 | # error "CAIRO_MUTEX_IMPL_UNLOCK not defined" |
||
140 | #endif |
||
141 | #ifndef CAIRO_MUTEX_IMPL_INIT |
||
142 | # error "CAIRO_MUTEX_IMPL_INIT not defined" |
||
143 | #endif |
||
144 | #ifndef CAIRO_MUTEX_IMPL_FINI |
||
145 | # error "CAIRO_MUTEX_IMPL_FINI not defined" |
||
146 | #endif |
||
147 | #ifndef CAIRO_MUTEX_IMPL_NIL_INITIALIZER |
||
148 | # error "CAIRO_MUTEX_IMPL_NIL_INITIALIZER not defined" |
||
149 | #endif |
||
150 | |||
151 | |||
152 | /* Public interface. */ |
||
153 | |||
154 | /* By default it simply uses the implementation provided. |
||
155 | * But we can provide for debugging features by overriding them */ |
||
156 | |||
157 | #ifndef CAIRO_MUTEX_DEBUG |
||
158 | typedef cairo_mutex_impl_t cairo_mutex_t; |
||
159 | #else |
||
160 | # define cairo_mutex_t cairo_mutex_impl_t |
||
161 | #endif |
||
162 | |||
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 |
||
170 | |||
171 | #ifndef CAIRO_MUTEX_IS_LOCKED |
||
172 | # define CAIRO_MUTEX_IS_LOCKED(name) 1 |
||
173 | #endif |
||
174 | #ifndef CAIRO_MUTEX_IS_UNLOCKED |
||
175 | # define CAIRO_MUTEX_IS_UNLOCKED(name) 1 |
||
176 | #endif |
||
177 | |||
178 | |||
179 | /* Debugging support */ |
||
180 | |||
181 | #ifdef CAIRO_MUTEX_DEBUG |
||
182 | |||
183 | /* TODO add mutex debugging facilities here (eg deadlock detection) */ |
||
184 | |||
185 | #endif /* CAIRO_MUTEX_DEBUG */ |
||
186 | |||
187 | #endif |