~ubuntu-branches/ubuntu/precise/wget/precise-proposed

« back to all changes in this revision

Viewing changes to lib/glthread/lock.h

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-10-19 00:00:09 UTC
  • mfrom: (2.1.13 sid)
  • Revision ID: james.westby@ubuntu.com-20111019000009-8p33w3wz4b1rdri0
Tags: 1.13-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add wget-udeb to ship wget.gnu as alternative to busybox wget
    implementation.
  - Depend on libssl-dev 0.9.8k-7ubuntu4 (LP: #503339)
* Dropped changes, superseded in Debian:
  - Keep build dependencies in main:
    + debian/control: remove info2man build-dep
    + debian/patches/series: disable wget-infopod_generated_manpage
  - Mark wget Multi-Arch: foreign, so packages that aren't of the same arch
    can depend on it.
* Pass --with-ssl=openssl; we don't want to use gnutls, there's no udeb for
  it.
* Add a second build pass for the udeb, so we can build without libidn.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- buffer-read-only: t -*- vi: set ro: */
 
2
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
 
3
/* Locking in multithreaded situations.
 
4
   Copyright (C) 2005-2011 Free Software Foundation, Inc.
 
5
 
 
6
   This program is free software; you can redistribute it and/or modify
 
7
   it under the terms of the GNU General Public License as published by
 
8
   the Free Software Foundation; either version 3, or (at your option)
 
9
   any later version.
 
10
 
 
11
   This program is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
   GNU General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program; if not, write to the Free Software Foundation,
 
18
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
19
 
 
20
/* Written by Bruno Haible <bruno@clisp.org>, 2005.
 
21
   Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h,
 
22
   gthr-win32.h.  */
 
23
 
 
24
/* This file contains locking primitives for use with a given thread library.
 
25
   It does not contain primitives for creating threads or for other
 
26
   synchronization primitives.
 
27
 
 
28
   Normal (non-recursive) locks:
 
29
     Type:                gl_lock_t
 
30
     Declaration:         gl_lock_define(extern, name)
 
31
     Initializer:         gl_lock_define_initialized(, name)
 
32
     Initialization:      gl_lock_init (name);
 
33
     Taking the lock:     gl_lock_lock (name);
 
34
     Releasing the lock:  gl_lock_unlock (name);
 
35
     De-initialization:   gl_lock_destroy (name);
 
36
   Equivalent functions with control of error handling:
 
37
     Initialization:      err = glthread_lock_init (&name);
 
38
     Taking the lock:     err = glthread_lock_lock (&name);
 
39
     Releasing the lock:  err = glthread_lock_unlock (&name);
 
40
     De-initialization:   err = glthread_lock_destroy (&name);
 
41
 
 
42
   Read-Write (non-recursive) locks:
 
43
     Type:                gl_rwlock_t
 
44
     Declaration:         gl_rwlock_define(extern, name)
 
45
     Initializer:         gl_rwlock_define_initialized(, name)
 
46
     Initialization:      gl_rwlock_init (name);
 
47
     Taking the lock:     gl_rwlock_rdlock (name);
 
48
                          gl_rwlock_wrlock (name);
 
49
     Releasing the lock:  gl_rwlock_unlock (name);
 
50
     De-initialization:   gl_rwlock_destroy (name);
 
51
   Equivalent functions with control of error handling:
 
52
     Initialization:      err = glthread_rwlock_init (&name);
 
53
     Taking the lock:     err = glthread_rwlock_rdlock (&name);
 
54
                          err = glthread_rwlock_wrlock (&name);
 
55
     Releasing the lock:  err = glthread_rwlock_unlock (&name);
 
56
     De-initialization:   err = glthread_rwlock_destroy (&name);
 
57
 
 
58
   Recursive locks:
 
59
     Type:                gl_recursive_lock_t
 
60
     Declaration:         gl_recursive_lock_define(extern, name)
 
61
     Initializer:         gl_recursive_lock_define_initialized(, name)
 
62
     Initialization:      gl_recursive_lock_init (name);
 
63
     Taking the lock:     gl_recursive_lock_lock (name);
 
64
     Releasing the lock:  gl_recursive_lock_unlock (name);
 
65
     De-initialization:   gl_recursive_lock_destroy (name);
 
66
   Equivalent functions with control of error handling:
 
67
     Initialization:      err = glthread_recursive_lock_init (&name);
 
68
     Taking the lock:     err = glthread_recursive_lock_lock (&name);
 
69
     Releasing the lock:  err = glthread_recursive_lock_unlock (&name);
 
70
     De-initialization:   err = glthread_recursive_lock_destroy (&name);
 
71
 
 
72
  Once-only execution:
 
73
     Type:                gl_once_t
 
74
     Initializer:         gl_once_define(extern, name)
 
75
     Execution:           gl_once (name, initfunction);
 
76
   Equivalent functions with control of error handling:
 
77
     Execution:           err = glthread_once (&name, initfunction);
 
78
*/
 
79
 
 
80
 
 
81
#ifndef _LOCK_H
 
82
#define _LOCK_H
 
83
 
 
84
#include <errno.h>
 
85
#include <stdlib.h>
 
86
 
 
87
/* ========================================================================= */
 
88
 
 
89
#if USE_POSIX_THREADS
 
90
 
 
91
/* Use the POSIX threads library.  */
 
92
 
 
93
# include <pthread.h>
 
94
 
 
95
# ifdef __cplusplus
 
96
extern "C" {
 
97
# endif
 
98
 
 
99
# if PTHREAD_IN_USE_DETECTION_HARD
 
100
 
 
101
/* The pthread_in_use() detection needs to be done at runtime.  */
 
102
#  define pthread_in_use() \
 
103
     glthread_in_use ()
 
104
extern int glthread_in_use (void);
 
105
 
 
106
# endif
 
107
 
 
108
# if USE_POSIX_THREADS_WEAK
 
109
 
 
110
/* Use weak references to the POSIX threads library.  */
 
111
 
 
112
/* Weak references avoid dragging in external libraries if the other parts
 
113
   of the program don't use them.  Here we use them, because we don't want
 
114
   every program that uses libintl to depend on libpthread.  This assumes
 
115
   that libpthread would not be loaded after libintl; i.e. if libintl is
 
116
   loaded first, by an executable that does not depend on libpthread, and
 
117
   then a module is dynamically loaded that depends on libpthread, libintl
 
118
   will not be multithread-safe.  */
 
119
 
 
120
/* The way to test at runtime whether libpthread is present is to test
 
121
   whether a function pointer's value, such as &pthread_mutex_init, is
 
122
   non-NULL.  However, some versions of GCC have a bug through which, in
 
123
   PIC mode, &foo != NULL always evaluates to true if there is a direct
 
124
   call to foo(...) in the same function.  To avoid this, we test the
 
125
   address of a function in libpthread that we don't use.  */
 
126
 
 
127
#  pragma weak pthread_mutex_init
 
128
#  pragma weak pthread_mutex_lock
 
129
#  pragma weak pthread_mutex_unlock
 
130
#  pragma weak pthread_mutex_destroy
 
131
#  pragma weak pthread_rwlock_init
 
132
#  pragma weak pthread_rwlock_rdlock
 
133
#  pragma weak pthread_rwlock_wrlock
 
134
#  pragma weak pthread_rwlock_unlock
 
135
#  pragma weak pthread_rwlock_destroy
 
136
#  pragma weak pthread_once
 
137
#  pragma weak pthread_cond_init
 
138
#  pragma weak pthread_cond_wait
 
139
#  pragma weak pthread_cond_signal
 
140
#  pragma weak pthread_cond_broadcast
 
141
#  pragma weak pthread_cond_destroy
 
142
#  pragma weak pthread_mutexattr_init
 
143
#  pragma weak pthread_mutexattr_settype
 
144
#  pragma weak pthread_mutexattr_destroy
 
145
#  ifndef pthread_self
 
146
#   pragma weak pthread_self
 
147
#  endif
 
148
 
 
149
#  if !PTHREAD_IN_USE_DETECTION_HARD
 
150
#   pragma weak pthread_cancel
 
151
#   define pthread_in_use() (pthread_cancel != NULL)
 
152
#  endif
 
153
 
 
154
# else
 
155
 
 
156
#  if !PTHREAD_IN_USE_DETECTION_HARD
 
157
#   define pthread_in_use() 1
 
158
#  endif
 
159
 
 
160
# endif
 
161
 
 
162
/* -------------------------- gl_lock_t datatype -------------------------- */
 
163
 
 
164
typedef pthread_mutex_t gl_lock_t;
 
165
# define gl_lock_define(STORAGECLASS, NAME) \
 
166
    STORAGECLASS pthread_mutex_t NAME;
 
167
# define gl_lock_define_initialized(STORAGECLASS, NAME) \
 
168
    STORAGECLASS pthread_mutex_t NAME = gl_lock_initializer;
 
169
# define gl_lock_initializer \
 
170
    PTHREAD_MUTEX_INITIALIZER
 
171
# define glthread_lock_init(LOCK) \
 
172
    (pthread_in_use () ? pthread_mutex_init (LOCK, NULL) : 0)
 
173
# define glthread_lock_lock(LOCK) \
 
174
    (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0)
 
175
# define glthread_lock_unlock(LOCK) \
 
176
    (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0)
 
177
# define glthread_lock_destroy(LOCK) \
 
178
    (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0)
 
179
 
 
180
/* ------------------------- gl_rwlock_t datatype ------------------------- */
 
181
 
 
182
# if HAVE_PTHREAD_RWLOCK
 
183
 
 
184
#  ifdef PTHREAD_RWLOCK_INITIALIZER
 
185
 
 
186
typedef pthread_rwlock_t gl_rwlock_t;
 
187
#   define gl_rwlock_define(STORAGECLASS, NAME) \
 
188
      STORAGECLASS pthread_rwlock_t NAME;
 
189
#   define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
 
190
      STORAGECLASS pthread_rwlock_t NAME = gl_rwlock_initializer;
 
191
#   define gl_rwlock_initializer \
 
192
      PTHREAD_RWLOCK_INITIALIZER
 
193
#   define glthread_rwlock_init(LOCK) \
 
194
      (pthread_in_use () ? pthread_rwlock_init (LOCK, NULL) : 0)
 
195
#   define glthread_rwlock_rdlock(LOCK) \
 
196
      (pthread_in_use () ? pthread_rwlock_rdlock (LOCK) : 0)
 
197
#   define glthread_rwlock_wrlock(LOCK) \
 
198
      (pthread_in_use () ? pthread_rwlock_wrlock (LOCK) : 0)
 
199
#   define glthread_rwlock_unlock(LOCK) \
 
200
      (pthread_in_use () ? pthread_rwlock_unlock (LOCK) : 0)
 
201
#   define glthread_rwlock_destroy(LOCK) \
 
202
      (pthread_in_use () ? pthread_rwlock_destroy (LOCK) : 0)
 
203
 
 
204
#  else
 
205
 
 
206
typedef struct
 
207
        {
 
208
          int initialized;
 
209
          pthread_mutex_t guard;   /* protects the initialization */
 
210
          pthread_rwlock_t rwlock; /* read-write lock */
 
211
        }
 
212
        gl_rwlock_t;
 
213
#   define gl_rwlock_define(STORAGECLASS, NAME) \
 
214
      STORAGECLASS gl_rwlock_t NAME;
 
215
#   define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
 
216
      STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer;
 
217
#   define gl_rwlock_initializer \
 
218
      { 0, PTHREAD_MUTEX_INITIALIZER }
 
219
#   define glthread_rwlock_init(LOCK) \
 
220
      (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0)
 
221
#   define glthread_rwlock_rdlock(LOCK) \
 
222
      (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0)
 
223
#   define glthread_rwlock_wrlock(LOCK) \
 
224
      (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0)
 
225
#   define glthread_rwlock_unlock(LOCK) \
 
226
      (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0)
 
227
#   define glthread_rwlock_destroy(LOCK) \
 
228
      (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0)
 
229
extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock);
 
230
extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock);
 
231
extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock);
 
232
extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock);
 
233
extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock);
 
234
 
 
235
#  endif
 
236
 
 
237
# else
 
238
 
 
239
typedef struct
 
240
        {
 
241
          pthread_mutex_t lock; /* protects the remaining fields */
 
242
          pthread_cond_t waiting_readers; /* waiting readers */
 
243
          pthread_cond_t waiting_writers; /* waiting writers */
 
244
          unsigned int waiting_writers_count; /* number of waiting writers */
 
245
          int runcount; /* number of readers running, or -1 when a writer runs */
 
246
        }
 
247
        gl_rwlock_t;
 
248
# define gl_rwlock_define(STORAGECLASS, NAME) \
 
249
    STORAGECLASS gl_rwlock_t NAME;
 
250
# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
 
251
    STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer;
 
252
# define gl_rwlock_initializer \
 
253
    { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0 }
 
254
# define glthread_rwlock_init(LOCK) \
 
255
    (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0)
 
256
# define glthread_rwlock_rdlock(LOCK) \
 
257
    (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0)
 
258
# define glthread_rwlock_wrlock(LOCK) \
 
259
    (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0)
 
260
# define glthread_rwlock_unlock(LOCK) \
 
261
    (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0)
 
262
# define glthread_rwlock_destroy(LOCK) \
 
263
    (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0)
 
264
extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock);
 
265
extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock);
 
266
extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock);
 
267
extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock);
 
268
extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock);
 
269
 
 
270
# endif
 
271
 
 
272
/* --------------------- gl_recursive_lock_t datatype --------------------- */
 
273
 
 
274
# if HAVE_PTHREAD_MUTEX_RECURSIVE
 
275
 
 
276
#  if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
 
277
 
 
278
typedef pthread_mutex_t gl_recursive_lock_t;
 
279
#   define gl_recursive_lock_define(STORAGECLASS, NAME) \
 
280
      STORAGECLASS pthread_mutex_t NAME;
 
281
#   define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
 
282
      STORAGECLASS pthread_mutex_t NAME = gl_recursive_lock_initializer;
 
283
#   ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER
 
284
#    define gl_recursive_lock_initializer \
 
285
       PTHREAD_RECURSIVE_MUTEX_INITIALIZER
 
286
#   else
 
287
#    define gl_recursive_lock_initializer \
 
288
       PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
 
289
#   endif
 
290
#   define glthread_recursive_lock_init(LOCK) \
 
291
      (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0)
 
292
#   define glthread_recursive_lock_lock(LOCK) \
 
293
      (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0)
 
294
#   define glthread_recursive_lock_unlock(LOCK) \
 
295
      (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0)
 
296
#   define glthread_recursive_lock_destroy(LOCK) \
 
297
      (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0)
 
298
extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock);
 
299
 
 
300
#  else
 
301
 
 
302
typedef struct
 
303
        {
 
304
          pthread_mutex_t recmutex; /* recursive mutex */
 
305
          pthread_mutex_t guard;    /* protects the initialization */
 
306
          int initialized;
 
307
        }
 
308
        gl_recursive_lock_t;
 
309
#   define gl_recursive_lock_define(STORAGECLASS, NAME) \
 
310
      STORAGECLASS gl_recursive_lock_t NAME;
 
311
#   define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
 
312
      STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
 
313
#   define gl_recursive_lock_initializer \
 
314
      { PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, 0 }
 
315
#   define glthread_recursive_lock_init(LOCK) \
 
316
      (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0)
 
317
#   define glthread_recursive_lock_lock(LOCK) \
 
318
      (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0)
 
319
#   define glthread_recursive_lock_unlock(LOCK) \
 
320
      (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0)
 
321
#   define glthread_recursive_lock_destroy(LOCK) \
 
322
      (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0)
 
323
extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock);
 
324
extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock);
 
325
extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock);
 
326
extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock);
 
327
 
 
328
#  endif
 
329
 
 
330
# else
 
331
 
 
332
/* Old versions of POSIX threads on Solaris did not have recursive locks.
 
333
   We have to implement them ourselves.  */
 
334
 
 
335
typedef struct
 
336
        {
 
337
          pthread_mutex_t mutex;
 
338
          pthread_t owner;
 
339
          unsigned long depth;
 
340
        }
 
341
        gl_recursive_lock_t;
 
342
#  define gl_recursive_lock_define(STORAGECLASS, NAME) \
 
343
     STORAGECLASS gl_recursive_lock_t NAME;
 
344
#  define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
 
345
     STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
 
346
#  define gl_recursive_lock_initializer \
 
347
     { PTHREAD_MUTEX_INITIALIZER, (pthread_t) 0, 0 }
 
348
#  define glthread_recursive_lock_init(LOCK) \
 
349
     (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0)
 
350
#  define glthread_recursive_lock_lock(LOCK) \
 
351
     (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0)
 
352
#  define glthread_recursive_lock_unlock(LOCK) \
 
353
     (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0)
 
354
#  define glthread_recursive_lock_destroy(LOCK) \
 
355
     (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0)
 
356
extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock);
 
357
extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock);
 
358
extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock);
 
359
extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock);
 
360
 
 
361
# endif
 
362
 
 
363
/* -------------------------- gl_once_t datatype -------------------------- */
 
364
 
 
365
typedef pthread_once_t gl_once_t;
 
366
# define gl_once_define(STORAGECLASS, NAME) \
 
367
    STORAGECLASS pthread_once_t NAME = PTHREAD_ONCE_INIT;
 
368
# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
 
369
    (pthread_in_use ()                                                         \
 
370
     ? pthread_once (ONCE_CONTROL, INITFUNCTION)                               \
 
371
     : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0))
 
372
extern int glthread_once_singlethreaded (pthread_once_t *once_control);
 
373
 
 
374
# ifdef __cplusplus
 
375
}
 
376
# endif
 
377
 
 
378
#endif
 
379
 
 
380
/* ========================================================================= */
 
381
 
 
382
#if USE_PTH_THREADS
 
383
 
 
384
/* Use the GNU Pth threads library.  */
 
385
 
 
386
# include <pth.h>
 
387
 
 
388
# ifdef __cplusplus
 
389
extern "C" {
 
390
# endif
 
391
 
 
392
# if USE_PTH_THREADS_WEAK
 
393
 
 
394
/* Use weak references to the GNU Pth threads library.  */
 
395
 
 
396
#  pragma weak pth_mutex_init
 
397
#  pragma weak pth_mutex_acquire
 
398
#  pragma weak pth_mutex_release
 
399
#  pragma weak pth_rwlock_init
 
400
#  pragma weak pth_rwlock_acquire
 
401
#  pragma weak pth_rwlock_release
 
402
#  pragma weak pth_once
 
403
 
 
404
#  pragma weak pth_cancel
 
405
#  define pth_in_use() (pth_cancel != NULL)
 
406
 
 
407
# else
 
408
 
 
409
#  define pth_in_use() 1
 
410
 
 
411
# endif
 
412
 
 
413
/* -------------------------- gl_lock_t datatype -------------------------- */
 
414
 
 
415
typedef pth_mutex_t gl_lock_t;
 
416
# define gl_lock_define(STORAGECLASS, NAME) \
 
417
    STORAGECLASS pth_mutex_t NAME;
 
418
# define gl_lock_define_initialized(STORAGECLASS, NAME) \
 
419
    STORAGECLASS pth_mutex_t NAME = gl_lock_initializer;
 
420
# define gl_lock_initializer \
 
421
    PTH_MUTEX_INIT
 
422
# define glthread_lock_init(LOCK) \
 
423
    (pth_in_use () && !pth_mutex_init (LOCK) ? errno : 0)
 
424
# define glthread_lock_lock(LOCK) \
 
425
    (pth_in_use () && !pth_mutex_acquire (LOCK, 0, NULL) ? errno : 0)
 
426
# define glthread_lock_unlock(LOCK) \
 
427
    (pth_in_use () && !pth_mutex_release (LOCK) ? errno : 0)
 
428
# define glthread_lock_destroy(LOCK) \
 
429
    ((void)(LOCK), 0)
 
430
 
 
431
/* ------------------------- gl_rwlock_t datatype ------------------------- */
 
432
 
 
433
typedef pth_rwlock_t gl_rwlock_t;
 
434
#  define gl_rwlock_define(STORAGECLASS, NAME) \
 
435
     STORAGECLASS pth_rwlock_t NAME;
 
436
#  define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
 
437
     STORAGECLASS pth_rwlock_t NAME = gl_rwlock_initializer;
 
438
#  define gl_rwlock_initializer \
 
439
     PTH_RWLOCK_INIT
 
440
#  define glthread_rwlock_init(LOCK) \
 
441
     (pth_in_use () && !pth_rwlock_init (LOCK) ? errno : 0)
 
442
#  define glthread_rwlock_rdlock(LOCK) \
 
443
     (pth_in_use () && !pth_rwlock_acquire (LOCK, PTH_RWLOCK_RD, 0, NULL) ? errno : 0)
 
444
#  define glthread_rwlock_wrlock(LOCK) \
 
445
     (pth_in_use () && !pth_rwlock_acquire (LOCK, PTH_RWLOCK_RW, 0, NULL) ? errno : 0)
 
446
#  define glthread_rwlock_unlock(LOCK) \
 
447
     (pth_in_use () && !pth_rwlock_release (LOCK) ? errno : 0)
 
448
#  define glthread_rwlock_destroy(LOCK) \
 
449
     ((void)(LOCK), 0)
 
450
 
 
451
/* --------------------- gl_recursive_lock_t datatype --------------------- */
 
452
 
 
453
/* In Pth, mutexes are recursive by default.  */
 
454
typedef pth_mutex_t gl_recursive_lock_t;
 
455
#  define gl_recursive_lock_define(STORAGECLASS, NAME) \
 
456
     STORAGECLASS pth_mutex_t NAME;
 
457
#  define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
 
458
     STORAGECLASS pth_mutex_t NAME = gl_recursive_lock_initializer;
 
459
#  define gl_recursive_lock_initializer \
 
460
     PTH_MUTEX_INIT
 
461
#  define glthread_recursive_lock_init(LOCK) \
 
462
     (pth_in_use () && !pth_mutex_init (LOCK) ? errno : 0)
 
463
#  define glthread_recursive_lock_lock(LOCK) \
 
464
     (pth_in_use () && !pth_mutex_acquire (LOCK, 0, NULL) ? errno : 0)
 
465
#  define glthread_recursive_lock_unlock(LOCK) \
 
466
     (pth_in_use () && !pth_mutex_release (LOCK) ? errno : 0)
 
467
#  define glthread_recursive_lock_destroy(LOCK) \
 
468
     ((void)(LOCK), 0)
 
469
 
 
470
/* -------------------------- gl_once_t datatype -------------------------- */
 
471
 
 
472
typedef pth_once_t gl_once_t;
 
473
# define gl_once_define(STORAGECLASS, NAME) \
 
474
    STORAGECLASS pth_once_t NAME = PTH_ONCE_INIT;
 
475
# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
 
476
    (pth_in_use ()                                                             \
 
477
     ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION)                \
 
478
     : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0))
 
479
extern int glthread_once_multithreaded (pth_once_t *once_control, void (*initfunction) (void));
 
480
extern int glthread_once_singlethreaded (pth_once_t *once_control);
 
481
 
 
482
# ifdef __cplusplus
 
483
}
 
484
# endif
 
485
 
 
486
#endif
 
487
 
 
488
/* ========================================================================= */
 
489
 
 
490
#if USE_SOLARIS_THREADS
 
491
 
 
492
/* Use the old Solaris threads library.  */
 
493
 
 
494
# include <thread.h>
 
495
# include <synch.h>
 
496
 
 
497
# ifdef __cplusplus
 
498
extern "C" {
 
499
# endif
 
500
 
 
501
# if USE_SOLARIS_THREADS_WEAK
 
502
 
 
503
/* Use weak references to the old Solaris threads library.  */
 
504
 
 
505
#  pragma weak mutex_init
 
506
#  pragma weak mutex_lock
 
507
#  pragma weak mutex_unlock
 
508
#  pragma weak mutex_destroy
 
509
#  pragma weak rwlock_init
 
510
#  pragma weak rw_rdlock
 
511
#  pragma weak rw_wrlock
 
512
#  pragma weak rw_unlock
 
513
#  pragma weak rwlock_destroy
 
514
#  pragma weak thr_self
 
515
 
 
516
#  pragma weak thr_suspend
 
517
#  define thread_in_use() (thr_suspend != NULL)
 
518
 
 
519
# else
 
520
 
 
521
#  define thread_in_use() 1
 
522
 
 
523
# endif
 
524
 
 
525
/* -------------------------- gl_lock_t datatype -------------------------- */
 
526
 
 
527
typedef mutex_t gl_lock_t;
 
528
# define gl_lock_define(STORAGECLASS, NAME) \
 
529
    STORAGECLASS mutex_t NAME;
 
530
# define gl_lock_define_initialized(STORAGECLASS, NAME) \
 
531
    STORAGECLASS mutex_t NAME = gl_lock_initializer;
 
532
# define gl_lock_initializer \
 
533
    DEFAULTMUTEX
 
534
# define glthread_lock_init(LOCK) \
 
535
    (thread_in_use () ? mutex_init (LOCK, USYNC_THREAD, NULL) : 0)
 
536
# define glthread_lock_lock(LOCK) \
 
537
    (thread_in_use () ? mutex_lock (LOCK) : 0)
 
538
# define glthread_lock_unlock(LOCK) \
 
539
    (thread_in_use () ? mutex_unlock (LOCK) : 0)
 
540
# define glthread_lock_destroy(LOCK) \
 
541
    (thread_in_use () ? mutex_destroy (LOCK) : 0)
 
542
 
 
543
/* ------------------------- gl_rwlock_t datatype ------------------------- */
 
544
 
 
545
typedef rwlock_t gl_rwlock_t;
 
546
# define gl_rwlock_define(STORAGECLASS, NAME) \
 
547
    STORAGECLASS rwlock_t NAME;
 
548
# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
 
549
    STORAGECLASS rwlock_t NAME = gl_rwlock_initializer;
 
550
# define gl_rwlock_initializer \
 
551
    DEFAULTRWLOCK
 
552
# define glthread_rwlock_init(LOCK) \
 
553
    (thread_in_use () ? rwlock_init (LOCK, USYNC_THREAD, NULL) : 0)
 
554
# define glthread_rwlock_rdlock(LOCK) \
 
555
    (thread_in_use () ? rw_rdlock (LOCK) : 0)
 
556
# define glthread_rwlock_wrlock(LOCK) \
 
557
    (thread_in_use () ? rw_wrlock (LOCK) : 0)
 
558
# define glthread_rwlock_unlock(LOCK) \
 
559
    (thread_in_use () ? rw_unlock (LOCK) : 0)
 
560
# define glthread_rwlock_destroy(LOCK) \
 
561
    (thread_in_use () ? rwlock_destroy (LOCK) : 0)
 
562
 
 
563
/* --------------------- gl_recursive_lock_t datatype --------------------- */
 
564
 
 
565
/* Old Solaris threads did not have recursive locks.
 
566
   We have to implement them ourselves.  */
 
567
 
 
568
typedef struct
 
569
        {
 
570
          mutex_t mutex;
 
571
          thread_t owner;
 
572
          unsigned long depth;
 
573
        }
 
574
        gl_recursive_lock_t;
 
575
# define gl_recursive_lock_define(STORAGECLASS, NAME) \
 
576
    STORAGECLASS gl_recursive_lock_t NAME;
 
577
# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
 
578
    STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
 
579
# define gl_recursive_lock_initializer \
 
580
    { DEFAULTMUTEX, (thread_t) 0, 0 }
 
581
# define glthread_recursive_lock_init(LOCK) \
 
582
    (thread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0)
 
583
# define glthread_recursive_lock_lock(LOCK) \
 
584
    (thread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0)
 
585
# define glthread_recursive_lock_unlock(LOCK) \
 
586
    (thread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0)
 
587
# define glthread_recursive_lock_destroy(LOCK) \
 
588
    (thread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0)
 
589
extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock);
 
590
extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock);
 
591
extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock);
 
592
extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock);
 
593
 
 
594
/* -------------------------- gl_once_t datatype -------------------------- */
 
595
 
 
596
typedef struct
 
597
        {
 
598
          volatile int inited;
 
599
          mutex_t mutex;
 
600
        }
 
601
        gl_once_t;
 
602
# define gl_once_define(STORAGECLASS, NAME) \
 
603
    STORAGECLASS gl_once_t NAME = { 0, DEFAULTMUTEX };
 
604
# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
 
605
    (thread_in_use ()                                                          \
 
606
     ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION)                \
 
607
     : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0))
 
608
extern int glthread_once_multithreaded (gl_once_t *once_control, void (*initfunction) (void));
 
609
extern int glthread_once_singlethreaded (gl_once_t *once_control);
 
610
 
 
611
# ifdef __cplusplus
 
612
}
 
613
# endif
 
614
 
 
615
#endif
 
616
 
 
617
/* ========================================================================= */
 
618
 
 
619
#if USE_WIN32_THREADS
 
620
 
 
621
# include <windows.h>
 
622
 
 
623
# ifdef __cplusplus
 
624
extern "C" {
 
625
# endif
 
626
 
 
627
/* We can use CRITICAL_SECTION directly, rather than the Win32 Event, Mutex,
 
628
   Semaphore types, because
 
629
     - we need only to synchronize inside a single process (address space),
 
630
       not inter-process locking,
 
631
     - we don't need to support trylock operations.  (TryEnterCriticalSection
 
632
       does not work on Windows 95/98/ME.  Packages that need trylock usually
 
633
       define their own mutex type.)  */
 
634
 
 
635
/* There is no way to statically initialize a CRITICAL_SECTION.  It needs
 
636
   to be done lazily, once only.  For this we need spinlocks.  */
 
637
 
 
638
typedef struct { volatile int done; volatile long started; } gl_spinlock_t;
 
639
 
 
640
/* -------------------------- gl_lock_t datatype -------------------------- */
 
641
 
 
642
typedef struct
 
643
        {
 
644
          gl_spinlock_t guard; /* protects the initialization */
 
645
          CRITICAL_SECTION lock;
 
646
        }
 
647
        gl_lock_t;
 
648
# define gl_lock_define(STORAGECLASS, NAME) \
 
649
    STORAGECLASS gl_lock_t NAME;
 
650
# define gl_lock_define_initialized(STORAGECLASS, NAME) \
 
651
    STORAGECLASS gl_lock_t NAME = gl_lock_initializer;
 
652
# define gl_lock_initializer \
 
653
    { { 0, -1 } }
 
654
# define glthread_lock_init(LOCK) \
 
655
    (glthread_lock_init_func (LOCK), 0)
 
656
# define glthread_lock_lock(LOCK) \
 
657
    glthread_lock_lock_func (LOCK)
 
658
# define glthread_lock_unlock(LOCK) \
 
659
    glthread_lock_unlock_func (LOCK)
 
660
# define glthread_lock_destroy(LOCK) \
 
661
    glthread_lock_destroy_func (LOCK)
 
662
extern void glthread_lock_init_func (gl_lock_t *lock);
 
663
extern int glthread_lock_lock_func (gl_lock_t *lock);
 
664
extern int glthread_lock_unlock_func (gl_lock_t *lock);
 
665
extern int glthread_lock_destroy_func (gl_lock_t *lock);
 
666
 
 
667
/* ------------------------- gl_rwlock_t datatype ------------------------- */
 
668
 
 
669
/* It is impossible to implement read-write locks using plain locks, without
 
670
   introducing an extra thread dedicated to managing read-write locks.
 
671
   Therefore here we need to use the low-level Event type.  */
 
672
 
 
673
typedef struct
 
674
        {
 
675
          HANDLE *array; /* array of waiting threads, each represented by an event */
 
676
          unsigned int count; /* number of waiting threads */
 
677
          unsigned int alloc; /* length of allocated array */
 
678
          unsigned int offset; /* index of first waiting thread in array */
 
679
        }
 
680
        gl_carray_waitqueue_t;
 
681
typedef struct
 
682
        {
 
683
          gl_spinlock_t guard; /* protects the initialization */
 
684
          CRITICAL_SECTION lock; /* protects the remaining fields */
 
685
          gl_carray_waitqueue_t waiting_readers; /* waiting readers */
 
686
          gl_carray_waitqueue_t waiting_writers; /* waiting writers */
 
687
          int runcount; /* number of readers running, or -1 when a writer runs */
 
688
        }
 
689
        gl_rwlock_t;
 
690
# define gl_rwlock_define(STORAGECLASS, NAME) \
 
691
    STORAGECLASS gl_rwlock_t NAME;
 
692
# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
 
693
    STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer;
 
694
# define gl_rwlock_initializer \
 
695
    { { 0, -1 } }
 
696
# define glthread_rwlock_init(LOCK) \
 
697
    (glthread_rwlock_init_func (LOCK), 0)
 
698
# define glthread_rwlock_rdlock(LOCK) \
 
699
    glthread_rwlock_rdlock_func (LOCK)
 
700
# define glthread_rwlock_wrlock(LOCK) \
 
701
    glthread_rwlock_wrlock_func (LOCK)
 
702
# define glthread_rwlock_unlock(LOCK) \
 
703
    glthread_rwlock_unlock_func (LOCK)
 
704
# define glthread_rwlock_destroy(LOCK) \
 
705
    glthread_rwlock_destroy_func (LOCK)
 
706
extern void glthread_rwlock_init_func (gl_rwlock_t *lock);
 
707
extern int glthread_rwlock_rdlock_func (gl_rwlock_t *lock);
 
708
extern int glthread_rwlock_wrlock_func (gl_rwlock_t *lock);
 
709
extern int glthread_rwlock_unlock_func (gl_rwlock_t *lock);
 
710
extern int glthread_rwlock_destroy_func (gl_rwlock_t *lock);
 
711
 
 
712
/* --------------------- gl_recursive_lock_t datatype --------------------- */
 
713
 
 
714
/* The Win32 documentation says that CRITICAL_SECTION already implements a
 
715
   recursive lock.  But we need not rely on it: It's easy to implement a
 
716
   recursive lock without this assumption.  */
 
717
 
 
718
typedef struct
 
719
        {
 
720
          gl_spinlock_t guard; /* protects the initialization */
 
721
          DWORD owner;
 
722
          unsigned long depth;
 
723
          CRITICAL_SECTION lock;
 
724
        }
 
725
        gl_recursive_lock_t;
 
726
# define gl_recursive_lock_define(STORAGECLASS, NAME) \
 
727
    STORAGECLASS gl_recursive_lock_t NAME;
 
728
# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
 
729
    STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
 
730
# define gl_recursive_lock_initializer \
 
731
    { { 0, -1 }, 0, 0 }
 
732
# define glthread_recursive_lock_init(LOCK) \
 
733
    (glthread_recursive_lock_init_func (LOCK), 0)
 
734
# define glthread_recursive_lock_lock(LOCK) \
 
735
    glthread_recursive_lock_lock_func (LOCK)
 
736
# define glthread_recursive_lock_unlock(LOCK) \
 
737
    glthread_recursive_lock_unlock_func (LOCK)
 
738
# define glthread_recursive_lock_destroy(LOCK) \
 
739
    glthread_recursive_lock_destroy_func (LOCK)
 
740
extern void glthread_recursive_lock_init_func (gl_recursive_lock_t *lock);
 
741
extern int glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock);
 
742
extern int glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock);
 
743
extern int glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock);
 
744
 
 
745
/* -------------------------- gl_once_t datatype -------------------------- */
 
746
 
 
747
typedef struct
 
748
        {
 
749
          volatile int inited;
 
750
          volatile long started;
 
751
          CRITICAL_SECTION lock;
 
752
        }
 
753
        gl_once_t;
 
754
# define gl_once_define(STORAGECLASS, NAME) \
 
755
    STORAGECLASS gl_once_t NAME = { -1, -1 };
 
756
# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
 
757
    (glthread_once_func (ONCE_CONTROL, INITFUNCTION), 0)
 
758
extern void glthread_once_func (gl_once_t *once_control, void (*initfunction) (void));
 
759
 
 
760
# ifdef __cplusplus
 
761
}
 
762
# endif
 
763
 
 
764
#endif
 
765
 
 
766
/* ========================================================================= */
 
767
 
 
768
#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WIN32_THREADS)
 
769
 
 
770
/* Provide dummy implementation if threads are not supported.  */
 
771
 
 
772
/* -------------------------- gl_lock_t datatype -------------------------- */
 
773
 
 
774
typedef int gl_lock_t;
 
775
# define gl_lock_define(STORAGECLASS, NAME)
 
776
# define gl_lock_define_initialized(STORAGECLASS, NAME)
 
777
# define glthread_lock_init(NAME) 0
 
778
# define glthread_lock_lock(NAME) 0
 
779
# define glthread_lock_unlock(NAME) 0
 
780
# define glthread_lock_destroy(NAME) 0
 
781
 
 
782
/* ------------------------- gl_rwlock_t datatype ------------------------- */
 
783
 
 
784
typedef int gl_rwlock_t;
 
785
# define gl_rwlock_define(STORAGECLASS, NAME)
 
786
# define gl_rwlock_define_initialized(STORAGECLASS, NAME)
 
787
# define glthread_rwlock_init(NAME) 0
 
788
# define glthread_rwlock_rdlock(NAME) 0
 
789
# define glthread_rwlock_wrlock(NAME) 0
 
790
# define glthread_rwlock_unlock(NAME) 0
 
791
# define glthread_rwlock_destroy(NAME) 0
 
792
 
 
793
/* --------------------- gl_recursive_lock_t datatype --------------------- */
 
794
 
 
795
typedef int gl_recursive_lock_t;
 
796
# define gl_recursive_lock_define(STORAGECLASS, NAME)
 
797
# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME)
 
798
# define glthread_recursive_lock_init(NAME) 0
 
799
# define glthread_recursive_lock_lock(NAME) 0
 
800
# define glthread_recursive_lock_unlock(NAME) 0
 
801
# define glthread_recursive_lock_destroy(NAME) 0
 
802
 
 
803
/* -------------------------- gl_once_t datatype -------------------------- */
 
804
 
 
805
typedef int gl_once_t;
 
806
# define gl_once_define(STORAGECLASS, NAME) \
 
807
    STORAGECLASS gl_once_t NAME = 0;
 
808
# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
 
809
    (*(ONCE_CONTROL) == 0 ? (*(ONCE_CONTROL) = ~ 0, INITFUNCTION (), 0) : 0)
 
810
 
 
811
#endif
 
812
 
 
813
/* ========================================================================= */
 
814
 
 
815
/* Macros with built-in error handling.  */
 
816
 
 
817
/* -------------------------- gl_lock_t datatype -------------------------- */
 
818
 
 
819
#define gl_lock_init(NAME) \
 
820
   do                                  \
 
821
     {                                 \
 
822
       if (glthread_lock_init (&NAME)) \
 
823
         abort ();                     \
 
824
     }                                 \
 
825
   while (0)
 
826
#define gl_lock_lock(NAME) \
 
827
   do                                  \
 
828
     {                                 \
 
829
       if (glthread_lock_lock (&NAME)) \
 
830
         abort ();                     \
 
831
     }                                 \
 
832
   while (0)
 
833
#define gl_lock_unlock(NAME) \
 
834
   do                                    \
 
835
     {                                   \
 
836
       if (glthread_lock_unlock (&NAME)) \
 
837
         abort ();                       \
 
838
     }                                   \
 
839
   while (0)
 
840
#define gl_lock_destroy(NAME) \
 
841
   do                                     \
 
842
     {                                    \
 
843
       if (glthread_lock_destroy (&NAME)) \
 
844
         abort ();                        \
 
845
     }                                    \
 
846
   while (0)
 
847
 
 
848
/* ------------------------- gl_rwlock_t datatype ------------------------- */
 
849
 
 
850
#define gl_rwlock_init(NAME) \
 
851
   do                                    \
 
852
     {                                   \
 
853
       if (glthread_rwlock_init (&NAME)) \
 
854
         abort ();                       \
 
855
     }                                   \
 
856
   while (0)
 
857
#define gl_rwlock_rdlock(NAME) \
 
858
   do                                      \
 
859
     {                                     \
 
860
       if (glthread_rwlock_rdlock (&NAME)) \
 
861
         abort ();                         \
 
862
     }                                     \
 
863
   while (0)
 
864
#define gl_rwlock_wrlock(NAME) \
 
865
   do                                      \
 
866
     {                                     \
 
867
       if (glthread_rwlock_wrlock (&NAME)) \
 
868
         abort ();                         \
 
869
     }                                     \
 
870
   while (0)
 
871
#define gl_rwlock_unlock(NAME) \
 
872
   do                                      \
 
873
     {                                     \
 
874
       if (glthread_rwlock_unlock (&NAME)) \
 
875
         abort ();                         \
 
876
     }                                     \
 
877
   while (0)
 
878
#define gl_rwlock_destroy(NAME) \
 
879
   do                                       \
 
880
     {                                      \
 
881
       if (glthread_rwlock_destroy (&NAME)) \
 
882
         abort ();                          \
 
883
     }                                      \
 
884
   while (0)
 
885
 
 
886
/* --------------------- gl_recursive_lock_t datatype --------------------- */
 
887
 
 
888
#define gl_recursive_lock_init(NAME) \
 
889
   do                                            \
 
890
     {                                           \
 
891
       if (glthread_recursive_lock_init (&NAME)) \
 
892
         abort ();                               \
 
893
     }                                           \
 
894
   while (0)
 
895
#define gl_recursive_lock_lock(NAME) \
 
896
   do                                            \
 
897
     {                                           \
 
898
       if (glthread_recursive_lock_lock (&NAME)) \
 
899
         abort ();                               \
 
900
     }                                           \
 
901
   while (0)
 
902
#define gl_recursive_lock_unlock(NAME) \
 
903
   do                                              \
 
904
     {                                             \
 
905
       if (glthread_recursive_lock_unlock (&NAME)) \
 
906
         abort ();                                 \
 
907
     }                                             \
 
908
   while (0)
 
909
#define gl_recursive_lock_destroy(NAME) \
 
910
   do                                               \
 
911
     {                                              \
 
912
       if (glthread_recursive_lock_destroy (&NAME)) \
 
913
         abort ();                                  \
 
914
     }                                              \
 
915
   while (0)
 
916
 
 
917
/* -------------------------- gl_once_t datatype -------------------------- */
 
918
 
 
919
#define gl_once(NAME, INITFUNCTION) \
 
920
   do                                           \
 
921
     {                                          \
 
922
       if (glthread_once (&NAME, INITFUNCTION)) \
 
923
         abort ();                              \
 
924
     }                                          \
 
925
   while (0)
 
926
 
 
927
/* ========================================================================= */
 
928
 
 
929
#endif /* _LOCK_H */