This source file includes following definitions.
- cnd_init
- mutex_lock
- mutex_unlock
- cnd_wait
- cnd_timedwait
- cnd_signal
- cnd_broadcast
- cnd_destroy
- cnd_init
- cnd_wait
- cnd_timedwait
- cnd_signal
- cnd_broadcast
- cnd_destroy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <config.h>
21
22 #include <threads.h>
23
24 #include <errno.h>
25 #include <stdlib.h>
26
27 #if defined _WIN32 && ! defined __CYGWIN__
28
29
30 # define WIN32_LEAN_AND_MEAN
31 # include <windows.h>
32
33 # include "windows-mutex.h"
34 # include "windows-recmutex.h"
35 # include "windows-timedmutex.h"
36 # include "windows-timedrecmutex.h"
37
38 #else
39
40
41 # include <pthread.h>
42
43 #endif
44
45 #if defined _WIN32 && ! defined __CYGWIN__
46
47
48 int
49 cnd_init (cnd_t *cond)
50 {
51 int err = glwthread_cond_init (cond);
52 return (err == 0 ? thrd_success :
53 err == ENOMEM ? thrd_nomem :
54 thrd_error);
55 }
56
57 static int
58 mutex_lock (mtx_t *mutex)
59 {
60 switch (mutex->type)
61 {
62 case mtx_plain:
63 return glwthread_mutex_lock (&mutex->u.u_mutex);
64 case mtx_plain | mtx_recursive:
65 return glwthread_recmutex_lock (&mutex->u.u_recmutex);
66 case mtx_timed:
67 return glwthread_timedmutex_lock (&mutex->u.u_timedmutex);
68 case mtx_timed | mtx_recursive:
69 return glwthread_timedrecmutex_lock (&mutex->u.u_timedrecmutex);
70 default:
71 abort ();
72 }
73 }
74
75 static int
76 mutex_unlock (mtx_t *mutex)
77 {
78 switch (mutex->type)
79 {
80 case mtx_plain:
81 return glwthread_mutex_unlock (&mutex->u.u_mutex);
82 case mtx_plain | mtx_recursive:
83 return glwthread_recmutex_unlock (&mutex->u.u_recmutex);
84 case mtx_timed:
85 return glwthread_timedmutex_unlock (&mutex->u.u_timedmutex);
86 case mtx_timed | mtx_recursive:
87 return glwthread_timedrecmutex_unlock (&mutex->u.u_timedrecmutex);
88 default:
89 abort ();
90 }
91 }
92
93 int
94 cnd_wait (cnd_t *cond, mtx_t *mutex)
95 {
96 int err = glwthread_cond_wait (cond, mutex,
97 (int (*) (void *)) mutex_lock,
98 (int (*) (void *)) mutex_unlock);
99 return (err == 0 ? thrd_success : thrd_error);
100 }
101
102 int
103 cnd_timedwait (cnd_t *cond, mtx_t *mutex, const struct timespec *abstime)
104 {
105 int err = glwthread_cond_timedwait (cond, mutex,
106 (int (*) (void *)) mutex_lock,
107 (int (*) (void *)) mutex_unlock,
108 abstime);
109 return (err == 0 ? thrd_success :
110 err == ETIMEDOUT ? thrd_timedout :
111 thrd_error);
112 }
113
114 int
115 cnd_signal (cnd_t *cond)
116 {
117 int err = glwthread_cond_signal (cond);
118 return (err == 0 ? thrd_success :
119 err == ENOMEM ? thrd_nomem :
120 thrd_error);
121 }
122
123 int
124 cnd_broadcast (cnd_t *cond)
125 {
126 int err = glwthread_cond_broadcast (cond);
127 return (err == 0 ? thrd_success : thrd_error);
128 }
129
130 void
131 cnd_destroy (cnd_t *cond)
132 {
133 glwthread_cond_destroy (cond);
134 }
135
136 #else
137
138
139 int
140 cnd_init (cnd_t *cond)
141 {
142 int err = pthread_cond_init (cond, NULL);
143 return (err == 0 ? thrd_success :
144 err == ENOMEM ? thrd_nomem :
145 thrd_error);
146 }
147
148 int
149 cnd_wait (cnd_t *cond, mtx_t *mutex)
150 {
151 int err = pthread_cond_wait (cond, mutex);
152 return (err == 0 ? thrd_success : thrd_error);
153 }
154
155 int
156 cnd_timedwait (cnd_t *cond, mtx_t *mutex, const struct timespec *abstime)
157 {
158 int err = pthread_cond_timedwait (cond, mutex, abstime);
159 return (err == 0 ? thrd_success :
160 err == ETIMEDOUT ? thrd_timedout :
161 thrd_error);
162 }
163
164 int
165 cnd_signal (cnd_t *cond)
166 {
167 int err = pthread_cond_signal (cond);
168 return (err == 0 ? thrd_success :
169 err == ENOMEM ? thrd_nomem :
170 thrd_error);
171 }
172
173 int
174 cnd_broadcast (cnd_t *cond)
175 {
176 int err = pthread_cond_broadcast (cond);
177 return (err == 0 ? thrd_success : thrd_error);
178 }
179
180 void
181 cnd_destroy (cnd_t *cond)
182 {
183 pthread_cond_destroy (cond);
184 }
185
186 #endif