~ubuntu-branches/ubuntu/hardy/libgdiplus/hardy

« back to all changes in this revision

Viewing changes to cairo/src/cairo-mutex-type-private.h

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2007-12-18 13:08:10 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20071218130810-hlmitxfddf6h511j
Tags: 1.2.6-1ubuntu1
* Sync with Debian:
  - debian/control:
    + Add lpia and sparc to the architectures. We support them.
    + Change Maintainer to Ubuntu Mono Team.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
 
53
53
/* A fully qualified no-operation statement */
54
54
#define CAIRO_MUTEX_NOOP        do {/*no-op*/} while (0)
55
 
 
56
 
 
 
55
/* And one that evaluates it's argument once */
 
56
#define CAIRO_MUTEX_NOOP1(expr)        do { if (expr) ; } while (0)
 
57
 
 
58
 
 
59
/* Cairo mutex implementation:
 
60
 *
 
61
 * Any new mutex implementation needs to do the following:
 
62
 *
 
63
 * - Condition on the right header or feature.  Headers are
 
64
 *   preferred as eg. you still can use win32 mutex implementation
 
65
 *   on a win32 system even if you do not compile the win32
 
66
 *   surface/backend.
 
67
 *
 
68
 * - typedef cairo_mutex_t to the proper mutex type on your target
 
69
 *   system.  Note that you may or may not need to use a pointer,
 
70
 *   depending on what kinds of initialization your mutex
 
71
 *   implementation supports.  No trailing semicolon needed.
 
72
 *   You should be able to compile the following snippet (don't try
 
73
 *   running it):
 
74
 *
 
75
 *      cairo_mutex_t _cairo_some_mutex;
 
76
 *
 
77
 * - #define CAIRO_MUTEX_LOCK(mutex) and CAIRO_MUTEX_UNLOCK(mutex) to
 
78
 *   proper statement to lock/unlock the mutex object passed in.
 
79
 *   You can (and should) assume that the mutex is already
 
80
 *   initialized, and is-not-already-locked/is-locked,
 
81
 *   respectively.  Use the "do { ... } while (0)" idiom if necessary.
 
82
 *   No trailing semicolons are needed (in any macro you define here).
 
83
 *   You should be able to compile the following snippet:
 
84
 *
 
85
 *      cairo_mutex_t _cairo_some_mutex;
 
86
 *
 
87
 *      if (1)
 
88
 *          CAIRO_MUTEX_LOCK (_cairo_some_mutex);
 
89
 *      else
 
90
 *          CAIRO_MUTEX_UNLOCK (_cairo_some_mutex);
 
91
 *
 
92
 * - #define CAIRO_MUTEX_NIL_INITIALIZER to something that can
 
93
 *   initialize the cairo_mutex_t type you defined.  Most of the
 
94
 *   time one of 0, NULL, or {} works.  At this point
 
95
 *   you should be able to compile the following snippet:
 
96
 *
 
97
 *      cairo_mutex_t _cairo_some_mutex = CAIRO_MUTEX_NIL_INITIALIZER;
 
98
 *
 
99
 *      if (1)
 
100
 *          CAIRO_MUTEX_LOCK (_cairo_some_mutex);
 
101
 *      else
 
102
 *          CAIRO_MUTEX_UNLOCK (_cairo_some_mutex);
 
103
 *
 
104
 * - If the above code is not enough to initialize a mutex on
 
105
 *   your platform, #define CAIRO_MUTEX_INIT(mutex) to statement
 
106
 *   to initialize the mutex (allocate resources, etc).  Such that
 
107
 *   you should be able to compile AND RUN the following snippet:
 
108
 *
 
109
 *      cairo_mutex_t _cairo_some_mutex = CAIRO_MUTEX_NIL_INITIALIZER;
 
110
 *
 
111
 *      CAIRO_MUTEX_INIT (_cairo_some_mutex);
 
112
 *
 
113
 *      if (1)
 
114
 *          CAIRO_MUTEX_LOCK (_cairo_some_mutex);
 
115
 *      else
 
116
 *          CAIRO_MUTEX_UNLOCK (_cairo_some_mutex);
 
117
 *
 
118
 * - If you define CAIRO_MUTEX_INIT(mutex), cairo will use it to
 
119
 *   initialize all static mutex'es.  If for any reason that should
 
120
 *   not happen (eg. CAIRO_MUTEX_INIT is just a faster way than
 
121
 *   what cairo does using CAIRO_MUTEX_NIL_INITIALIZER), then
 
122
 *   #define CAIRO_MUTEX_INITIALIZE() CAIRO_MUTEX_NOOP
 
123
 *
 
124
 * - If your system supports freeing a mutex object (deallocating
 
125
 *   resources, etc), then #define CAIRO_MUTEX_FINI(mutex) to do
 
126
 *   that.
 
127
 *
 
128
 * - If you define CAIRO_MUTEX_FINI(mutex), cairo will use it to
 
129
 *   define a finalizer function to finalize all static mutex'es.
 
130
 *   However, it's up to you to call CAIRO_MUTEX_FINALIZE() at
 
131
 *   proper places, eg. when the system is unloading the cairo library.
 
132
 *   So, if for any reason finalizing static mutex'es is not needed
 
133
 *   (eg. you never call CAIRO_MUTEX_FINALIZE), then
 
134
 *   #define CAIRO_MUTEX_FINALIZE() CAIRO_MUTEX_NOOP
 
135
 *
 
136
 * - That is all.  If for any reason you think the above API is
 
137
 *   not enough to implement cairo_mutex_t on your system, please
 
138
 *   stop and write to the cairo mailing list about it.  DO NOT
 
139
 *   poke around cairo-mutex-private.h for possible solutions.
 
140
 */
57
141
 
58
142
#if CAIRO_NO_MUTEX
59
143
 
62
146
  typedef int cairo_mutex_t;
63
147
 
64
148
# define CAIRO_MUTEX_INITIALIZE() CAIRO_MUTEX_NOOP
65
 
# define CAIRO_MUTEX_LOCK(name) do { while (name) ; (name) = 1; } while (0)
66
 
# define CAIRO_MUTEX_UNLOCK(name) (name) = 0
 
149
# define CAIRO_MUTEX_LOCK(mutex) do { while (mutex) ; (mutex) = 1; } while (0)
 
150
# define CAIRO_MUTEX_UNLOCK(mutex) (mutex) = 0
67
151
# define CAIRO_MUTEX_NIL_INITIALIZER 0
68
152
 
69
153
#elif HAVE_PTHREAD_H /*******************************************************/
72
156
 
73
157
  typedef pthread_mutex_t cairo_mutex_t;
74
158
 
75
 
# define CAIRO_MUTEX_INITIALIZE() CAIRO_MUTEX_NOOP
76
 
# define CAIRO_MUTEX_LOCK(name) pthread_mutex_lock (&(name))
77
 
# define CAIRO_MUTEX_UNLOCK(name) pthread_mutex_unlock (&(name))
78
 
# define CAIRO_MUTEX_FINI(mutex) pthread_mutex_destroy (mutex)
 
159
# define CAIRO_MUTEX_LOCK(mutex) pthread_mutex_lock (&(mutex))
 
160
# define CAIRO_MUTEX_UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
 
161
# define CAIRO_MUTEX_FINI(mutex) pthread_mutex_destroy (&(mutex))
 
162
# define CAIRO_MUTEX_FINALIZE() CAIRO_MUTEX_NOOP
79
163
# define CAIRO_MUTEX_NIL_INITIALIZER PTHREAD_MUTEX_INITIALIZER
80
164
 
81
165
#elif HAVE_WINDOWS_H /*******************************************************/
84
168
 
85
169
  typedef CRITICAL_SECTION cairo_mutex_t;
86
170
 
87
 
# define CAIRO_MUTEX_LOCK(name) EnterCriticalSection (&(name))
88
 
# define CAIRO_MUTEX_UNLOCK(name) LeaveCriticalSection (&(name))
89
 
# define CAIRO_MUTEX_INIT(mutex) InitializeCriticalSection (mutex)
90
 
# define CAIRO_MUTEX_FINI(mutex) DeleteCriticalSection (mutex)
 
171
# define CAIRO_MUTEX_LOCK(mutex) EnterCriticalSection (&(mutex))
 
172
# define CAIRO_MUTEX_UNLOCK(mutex) LeaveCriticalSection (&(mutex))
 
173
# define CAIRO_MUTEX_INIT(mutex) InitializeCriticalSection (&(mutex))
 
174
# define CAIRO_MUTEX_FINI(mutex) DeleteCriticalSection (&(mutex))
91
175
# define CAIRO_MUTEX_NIL_INITIALIZER { NULL, 0, 0, NULL, NULL, 0 }
92
176
 
93
177
#elif defined __OS2__ /******************************************************/
98
182
 
99
183
  typedef HMTX cairo_mutex_t;
100
184
 
101
 
# define CAIRO_MUTEX_LOCK(name) DosRequestMutexSem(name, SEM_INDEFINITE_WAIT)
102
 
# define CAIRO_MUTEX_UNLOCK(name) DosReleaseMutexSem(name)
103
 
# define CAIRO_MUTEX_INIT(mutex) DosCreateMutexSem (NULL, mutex, 0L, FALSE)
104
 
# define CAIRO_MUTEX_FINI(mutex) do {                           \
105
 
    if (0 != (mutex)) {                                         \
106
 
        DosCloseMutexSem (*(mutex));                            \
107
 
        (*(mutex)) = 0;                                         \
108
 
    }                                                           \
109
 
} while (0)
 
185
# define CAIRO_MUTEX_LOCK(mutex) DosRequestMutexSem(mutex, SEM_INDEFINITE_WAIT)
 
186
# define CAIRO_MUTEX_UNLOCK(mutex) DosReleaseMutexSem(mutex)
 
187
# define CAIRO_MUTEX_INIT(mutex) DosCreateMutexSem (NULL, &(mutex), 0L, FALSE)
 
188
# define CAIRO_MUTEX_FINI(mutex) DosCloseMutexSem (mutex)
110
189
# define CAIRO_MUTEX_NIL_INITIALIZER 0
111
190
 
112
191
#elif CAIRO_HAS_BEOS_SURFACE /***********************************************/
113
192
 
114
193
  typedef BLocker* cairo_mutex_t;
115
194
 
116
 
# define CAIRO_MUTEX_LOCK(name) (name)->Lock()
117
 
# define CAIRO_MUTEX_UNLOCK(name) (name)->Unlock()
118
 
# define CAIRO_MUTEX_INIT(mutex) (*(mutex)) = new BLocker()
119
 
# define CAIRO_MUTEX_FINI(mutex) delete (*(mutex))
 
195
# define CAIRO_MUTEX_LOCK(mutex) (mutex)->Lock()
 
196
# define CAIRO_MUTEX_UNLOCK(mutex) (mutex)->Unlock()
 
197
# define CAIRO_MUTEX_INIT(mutex) (mutex) = new BLocker()
 
198
# define CAIRO_MUTEX_FINI(mutex) delete (mutex)
120
199
# define CAIRO_MUTEX_NIL_INITIALIZER NULL
121
200
 
122
201
#else /**********************************************************************/
123
202
 
124
 
# error "XXX: No mutex implementation found.  Define CAIRO_NO_MUTEX to 1" \
125
 
        "     to compile cairo without thread-safety support."
 
203
# 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."
 
204
 
126
205
 
127
206
#endif
128
207