1 /*
2 * Copyright (c) 2011-2017 KO Myung-Hun <komh@chollian.net>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * os2threads to pthreads wrapper
24 */
25
26 #ifndef COMPAT_OS2THREADS_H
27 #define COMPAT_OS2THREADS_H
28
30 #define INCL_DOSERRORS
31 #include <os2.h>
32
33 #undef __STRICT_ANSI__ /* for _beginthread() */
34 #include <stdlib.h>
36
37 #include <sys/builtin.h>
38 #include <sys/fmutex.h>
39
43
46 void *(*start_routine)(
void *);
50
52
55
56 #define PTHREAD_MUTEX_INITIALIZER _FMUTEX_INITIALIZER
57
63
65
70
71 #define PTHREAD_ONCE_INIT {0, _FMUTEX_INITIALIZER}
72
74 {
76
78 }
79
82 void *(*start_routine)(void*),
84 {
88
90
91 return 0;
92 }
93
95 {
96 DosWaitThread(&thread.
tid, DCWW_WAIT);
97
98 if (value_ptr)
99 *value_ptr = thread.
result;
100
101 return 0;
102 }
103
106 {
107 _fmutex_create(
mutex, 0);
108
109 return 0;
110 }
111
113 {
114 _fmutex_close(
mutex);
115
116 return 0;
117 }
118
120 {
121 _fmutex_request(
mutex, 0);
122
123 return 0;
124 }
125
127 {
128 _fmutex_release(
mutex);
129
130 return 0;
131 }
132
135 {
136 DosCreateEventSem(
NULL, &
cond->event_sem, DCE_POSTONE, FALSE);
137 DosCreateEventSem(
NULL, &
cond->ack_sem, DCE_POSTONE, FALSE);
138
139 cond->wait_count = 0;
140
141 return 0;
142 }
143
145 {
146 DosCloseEventSem(
cond->event_sem);
147 DosCloseEventSem(
cond->ack_sem);
148
149 return 0;
150 }
151
153 {
154 if (!__atomic_cmpxchg32(&
cond->wait_count, 0, 0)) {
155 DosPostEventSem(
cond->event_sem);
156 DosWaitEventSem(
cond->ack_sem, SEM_INDEFINITE_WAIT);
157 }
158
159 return 0;
160 }
161
163 {
164 while (!__atomic_cmpxchg32(&
cond->wait_count, 0, 0))
166
167 return 0;
168 }
169
172 const struct timespec *abstime)
173 {
174 int64_t abs_milli = abstime->tv_sec * 1000LL + abstime->tv_nsec / 1000000;
176
177 __atomic_increment(&
cond->wait_count);
178
180
181 APIRET
ret = DosWaitEventSem(
cond->event_sem, t);
182
183 __atomic_decrement(&
cond->wait_count);
184
185 DosPostEventSem(
cond->ack_sem);
186
188
189 return (
ret == ERROR_TIMEOUT) ? ETIMEDOUT : 0;
190 }
191
194 {
195 __atomic_increment(&
cond->wait_count);
196
198
199 DosWaitEventSem(
cond->event_sem, SEM_INDEFINITE_WAIT);
200
201 __atomic_decrement(&
cond->wait_count);
202
203 DosPostEventSem(
cond->ack_sem);
204
206
207 return 0;
208 }
209
211 void (*init_routine)(void))
212 {
213 if (!once_control->
done)
214 {
215 _fmutex_request(&once_control->
mtx, 0);
216
217 if (!once_control->
done)
218 {
219 init_routine();
220
221 once_control->
done = 1;
222 }
223
224 _fmutex_release(&once_control->
mtx);
225 }
226
227 return 0;
228 }
229 #endif /* COMPAT_OS2THREADS_H */