1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/* Copyright (C) 2006 Manuel Novoa III <mjn3@codepoet.org>
*
* GNU Library General Public License (LGPL) version 2 or later.
*
* Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
*/
#ifndef _UCLIBC_MUTEX_H
#define _UCLIBC_MUTEX_H
#include <features.h>
#ifdef __UCLIBC_HAS_THREADS__
#include <pthread.h>
#ifdef _LIBC
#include <bits/uClibc_pthread.h>
#endif
#define __UCLIBC_MUTEX_TYPE pthread_mutex_t
#define __UCLIBC_MUTEX(M) pthread_mutex_t M
#define __UCLIBC_MUTEX_INIT(M,I) pthread_mutex_t M = I
#define __UCLIBC_MUTEX_STATIC(M,I) static pthread_mutex_t M = I
#define __UCLIBC_MUTEX_EXTERN(M) extern pthread_mutex_t M
#define __UCLIBC_MUTEX_INIT_VAR(M) \
((M) = (pthread_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
#define __UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE(M) \
__pthread_mutex_lock(&(M))
#define __UCLIBC_MUTEX_UNLOCK_CANCEL_UNSAFE(M) \
__pthread_mutex_unlock(&(M))
#define __UCLIBC_MUTEX_TRYLOCK_CANCEL_UNSAFE(M) \
__pthread_mutex_trylock(&(M))
#define __UCLIBC_MUTEX_CONDITIONAL_LOCK(M,C) \
do { \
struct _pthread_cleanup_buffer __infunc_pthread_cleanup_buffer; \
int __infunc_need_locking = (C); \
if (__infunc_need_locking) { \
_pthread_cleanup_push_defer(&__infunc_pthread_cleanup_buffer, \
(void (*) (void *))__pthread_mutex_unlock, \
&(M)); \
__pthread_mutex_lock(&(M)); \
} \
((void)0)
#define __UCLIBC_MUTEX_CONDITIONAL_UNLOCK(M,C) \
if (__infunc_need_locking) { \
_pthread_cleanup_pop_restore(&__infunc_pthread_cleanup_buffer,1); \
} \
} while (0)
#define __UCLIBC_MUTEX_AUTO_LOCK_VAR(A) int A
#define __UCLIBC_MUTEX_AUTO_LOCK(M,A,V) \
__UCLIBC_MUTEX_CONDITIONAL_LOCK(M,((A=(V)) == 0))
#define __UCLIBC_MUTEX_AUTO_UNLOCK(M,A) \
__UCLIBC_MUTEX_CONDITIONAL_UNLOCK(M,(A == 0))
#define __UCLIBC_MUTEX_LOCK(M) \
__UCLIBC_MUTEX_CONDITIONAL_LOCK(M, 1)
#define __UCLIBC_MUTEX_UNLOCK(M) \
__UCLIBC_MUTEX_CONDITIONAL_UNLOCK(M, 1)
#ifdef __USE_STDIO_FUTEXES__
#include <bits/stdio-lock.h>
#define __UCLIBC_IO_MUTEX(M) _IO_lock_t M
#define __UCLIBC_IO_MUTEX_LOCK(M) _IO_lock_lock(M)
#define __UCLIBC_IO_MUTEX_UNLOCK(M) _IO_lock_unlock(M)
#define __UCLIBC_IO_MUTEX_TRYLOCK(M) _IO_lock_trylock(M)
#define __UCLIBC_IO_MUTEX_INIT(M) _IO_lock_t M = _IO_lock_initializer
#define __UCLIBC_IO_MUTEX_EXTERN(M) extern _IO_lock_t M
#define __UCLIBC_IO_MUTEX_CONDITIONAL_LOCK(M,C) \
if (C) { \
_IO_lock_lock(M); \
}
#define __UCLIBC_IO_MUTEX_CONDITIONAL_UNLOCK(M,C) \
if (C) { \
_IO_lock_unlock(M); \
}
#define __UCLIBC_IO_MUTEX_AUTO_LOCK(M,A,V) \
__UCLIBC_IO_MUTEX_CONDITIONAL_LOCK(M,((A=(V))) == 0)
#define __UCLIBC_IO_MUTEX_AUTO_UNLOCK(M,A) \
__UCLIBC_IO_MUTEX_CONDITIONAL_UNLOCK(M,((A) == 0))
#define __UCLIBC_IO_MUTEX_LOCK_CANCEL_UNSAFE(M) _IO_lock_lock(M)
#define __UCLIBC_IO_MUTEX_UNLOCK_CANCEL_UNSAFE(M) _IO_lock_unlock(M)
#else /* of __USE_STDIO_FUTEXES__ */
#define __UCLIBC_IO_MUTEX(M) __UCLIBC_MUTEX(M)
#define __UCLIBC_IO_MUTEX_LOCK(M) __UCLIBC_MUTEX_CONDITIONAL_LOCK(M, 1)
#define __UCLIBC_IO_MUTEX_UNLOCK(M) __UCLIBC_MUTEX_CONDITIONAL_UNLOCK(M, 1)
#define __UCLIBC_IO_MUTEX_TRYLOCK(M) __UCLIBC_MUTEX_TRYLOCK_CANCEL_UNSAFE(M)
#define __UCLIBC_IO_MUTEX_INIT(M) __UCLIBC_MUTEX_INIT(M, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
#define __UCLIBC_IO_MUTEX_EXTERN(M) __UCLIBC_MUTEX_EXTERN(M)
#define __UCLIBC_IO_MUTEX_AUTO_LOCK(M,A,V) __UCLIBC_MUTEX_AUTO_LOCK(M,A,V)
#define __UCLIBC_IO_MUTEX_AUTO_UNLOCK(M,A) __UCLIBC_MUTEX_AUTO_UNLOCK(M,A)
#define __UCLIBC_IO_MUTEX_LOCK_CANCEL_UNSAFE(M) __UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE(M)
#define __UCLIBC_IO_MUTEX_UNLOCK_CANCEL_UNSAFE(M) __UCLIBC_MUTEX_UNLOCK_CANCEL_UNSAFE(M)
#define __UCLIBC_IO_MUTEX_CONDITIONAL_LOCK(M,C) __UCLIBC_MUTEX_CONDITIONAL_LOCK(M,C)
#define __UCLIBC_IO_MUTEX_CONDITIONAL_UNLOCK(M,C) __UCLIBC_MUTEX_CONDITIONAL_UNLOCK(M,C)
#endif /* of __USE_STDIO_FUTEXES__ */
#else /* of __UCLIBC_HAS_THREADS__ */
#define __UCLIBC_MUTEX(M) void *__UCLIBC_MUTEX_DUMMY_ ## M
#define __UCLIBC_MUTEX_INIT(M,I) extern void *__UCLIBC_MUTEX_DUMMY_ ## M
#define __UCLIBC_MUTEX_STATIC(M,I) extern void *__UCLIBC_MUTEX_DUMMY_ ## M
#define __UCLIBC_MUTEX_EXTERN(M) extern void *__UCLIBC_MUTEX_DUMMY_ ## M
#define __UCLIBC_MUTEX_INIT_VAR(M) ((void)0)
#define __UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE(M) ((void)0)
#define __UCLIBC_MUTEX_UNLOCK_CANCEL_UNSAFE(M) ((void)0)
#define __UCLIBC_MUTEX_TRYLOCK_CANCEL_UNSAFE(M) (0) /* Always succeed? */
#define __UCLIBC_MUTEX_CONDITIONAL_LOCK(M,C) ((void)0)
#define __UCLIBC_MUTEX_CONDITIONAL_UNLOCK(M,C) ((void)0)
#define __UCLIBC_MUTEX_AUTO_LOCK_VAR(A) ((void)0)
#define __UCLIBC_MUTEX_AUTO_LOCK(M,A,V) ((void)0)
#define __UCLIBC_MUTEX_AUTO_UNLOCK(M,A) ((void)0)
#define __UCLIBC_MUTEX_LOCK(M) ((void)0)
#define __UCLIBC_MUTEX_UNLOCK(M) ((void)0)
#define __UCLIBC_IO_MUTEX(M) __UCLIBC_MUTEX(M)
#define __UCLIBC_IO_MUTEX_LOCK(M) __UCLIBC_MUTEX_CONDITIONAL_LOCK(M, 1)
#define __UCLIBC_IO_MUTEX_UNLOCK(M) __UCLIBC_MUTEX_CONDITIONAL_UNLOCK(M, 1)
#define __UCLIBC_IO_MUTEX_TRYLOCK(M) __UCLIBC_MUTEX_TRYLOCK_CANCEL_UNSAFE(M)
#define __UCLIBC_IO_MUTEX_INIT(M) __UCLIBC_MUTEX_INIT(M, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
#define __UCLIBC_IO_MUTEX_EXTERN(M) __UCLIBC_MUTEX_EXTERN(M)
#define __UCLIBC_IO_MUTEX_AUTO_LOCK(M,A,V) __UCLIBC_MUTEX_AUTO_LOCK(M,A,V)
#define __UCLIBC_IO_MUTEX_AUTO_UNLOCK(M,A) __UCLIBC_MUTEX_AUTO_UNLOCK(M,A)
#define __UCLIBC_IO_MUTEX_LOCK_CANCEL_UNSAFE(M) __UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE(M)
#define __UCLIBC_IO_MUTEX_UNLOCK_CANCEL_UNSAFE(M) __UCLIBC_MUTEX_UNLOCK_CANCEL_UNSAFE(M)
#define __UCLIBC_IO_MUTEX_CONDITIONAL_LOCK(M,C) __UCLIBC_MUTEX_CONDITIONAL_LOCK(M,C)
#define __UCLIBC_IO_MUTEX_CONDITIONAL_UNLOCK(M,C) __UCLIBC_MUTEX_CONDITIONAL_UNLOCK(M,C)
#endif /* of __UCLIBC_HAS_THREADS__ */
#define __UCLIBC_IO_MUTEX_TRYLOCK_CANCEL_UNSAFE(M) \
__UCLIBC_IO_MUTEX_TRYLOCK(M)
#endif /* _UCLIBC_MUTEX_H */
|