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