42 |
42 |
|
43 |
43 |
#ifdef USE_POSIX_THREADS_WEAK
|
44 |
44 |
|
|
45 |
# pragma weak pthread_create
|
|
46 |
# pragma weak pthread_join
|
|
47 |
# pragma weak pthread_sigmask
|
|
48 |
# pragma weak pthread_once
|
|
49 |
# pragma weak pthread_exit
|
|
50 |
|
|
51 |
# ifdef HAVE_PTHREAD_ATFORK
|
|
52 |
# pragma weak pthread_atfork
|
|
53 |
# endif
|
|
54 |
|
|
55 |
# pragma weak pthread_mutex_init
|
|
56 |
# pragma weak pthread_mutex_lock
|
|
57 |
# pragma weak pthread_mutex_unlock
|
|
58 |
# pragma weak pthread_mutex_destroy
|
|
59 |
|
|
60 |
# pragma weak pthread_mutexattr_init
|
|
61 |
# pragma weak pthread_mutexattr_settype
|
|
62 |
# pragma weak pthread_mutexattr_destroy
|
|
63 |
|
|
64 |
# pragma weak pthread_cond_init
|
|
65 |
# pragma weak pthread_cond_wait
|
|
66 |
# pragma weak pthread_cond_signal
|
|
67 |
# pragma weak pthread_cond_broadcast
|
|
68 |
# pragma weak pthread_cond_timedwait
|
|
69 |
# pragma weak pthread_cond_destroy
|
|
70 |
|
|
71 |
# pragma weak pthread_condattr_init
|
|
72 |
# pragma weak pthread_condattr_setclock
|
|
73 |
|
|
74 |
# pragma weak pthread_getspecific
|
|
75 |
# pragma weak pthread_setspecific
|
|
76 |
|
|
77 |
# pragma weak pthread_key_delete
|
|
78 |
|
|
79 |
# ifndef pthread_self
|
|
80 |
# pragma weak pthread_self
|
|
81 |
# endif
|
|
82 |
|
45 |
83 |
# if !PTHREAD_IN_USE_DETECTION_HARD
|
46 |
84 |
# pragma weak pthread_cancel
|
47 |
85 |
# define __prelude_thread_in_use() (pthread_cancel != NULL)
|
... | ... | |
91 |
129 |
{
|
92 |
130 |
if ( ! need_init )
|
93 |
131 |
return;
|
94 |
|
|
|
132 |
|
95 |
133 |
pthread_key_create(&thread_error_key, thread_error_key_destroy);
|
96 |
134 |
need_init = FALSE;
|
97 |
135 |
}
|
... | ... | |
171 |
209 |
}
|
172 |
210 |
|
173 |
211 |
|
174 |
|
int prelude_thread_condattr_init(pthread_condattr_t *attr)
|
|
212 |
int prelude_thread_condattr_init(pthread_condattr_t *attr)
|
175 |
213 |
{
|
176 |
214 |
THR_FUNC(pthread_condattr_init(attr));
|
177 |
215 |
}
|
... | ... | |
228 |
266 |
{
|
229 |
267 |
if ( use_thread ) {
|
230 |
268 |
char *previous;
|
231 |
|
|
|
269 |
|
232 |
270 |
previous = pthread_getspecific(thread_error_key);
|
233 |
271 |
if ( previous )
|
234 |
272 |
free(previous);
|
235 |
|
|
|
273 |
|
236 |
274 |
pthread_key_delete(thread_error_key);
|
237 |
275 |
need_init = TRUE;
|
238 |
276 |
}
|
239 |
|
|
|
277 |
|
240 |
278 |
else if ( shared_error_buffer ) {
|
241 |
279 |
free(shared_error_buffer);
|
242 |
280 |
shared_error_buffer = NULL;
|
... | ... | |
262 |
300 |
int ret;
|
263 |
301 |
void *retval;
|
264 |
302 |
pthread_t thread;
|
265 |
|
|
|
303 |
|
266 |
304 |
ret = pthread_create(&thread, NULL, dummy_thread_func, NULL);
|
267 |
|
if ( ret != 0 )
|
|
305 |
if ( ret != 0 )
|
268 |
306 |
/* we're using libc stubs */
|
269 |
307 |
return FALSE;
|
270 |
308 |
|
... | ... | |
274 |
312 |
ret = pthread_join(thread, &retval);
|
275 |
313 |
if ( ret != 0 )
|
276 |
314 |
abort();
|
277 |
|
|
|
315 |
|
278 |
316 |
return TRUE;
|
279 |
317 |
}
|
280 |
318 |
|
... | ... | |
285 |
323 |
prelude_bool_t _prelude_thread_in_use(void)
|
286 |
324 |
{
|
287 |
325 |
static prelude_bool_t tested = FALSE;
|
288 |
|
|
|
326 |
|
289 |
327 |
if ( tested ) {
|
290 |
328 |
thread_init_if_needed();
|
291 |
329 |
return use_thread;
|
292 |
330 |
}
|
293 |
|
|
|
331 |
|
294 |
332 |
use_thread = __prelude_thread_in_use();
|
295 |
333 |
tested = TRUE;
|
296 |
334 |
|
297 |
335 |
prelude_log(PRELUDE_LOG_DEBUG, "[init] thread used=%d\n", use_thread);
|
298 |
336 |
thread_init_if_needed();
|
299 |
|
|
|
337 |
|
300 |
338 |
return use_thread;
|
301 |
339 |
}
|
302 |
340 |
|
... | ... | |
305 |
343 |
{
|
306 |
344 |
char *previous;
|
307 |
345 |
|
308 |
|
if ( ! use_thread ) {
|
|
346 |
if ( ! use_thread ) {
|
309 |
347 |
if ( shared_error_buffer )
|
310 |
348 |
free(shared_error_buffer);
|
311 |
|
|
|
349 |
|
312 |
350 |
shared_error_buffer = strdup(error);
|
313 |
351 |
}
|
314 |
352 |
|
... | ... | |
316 |
354 |
previous = pthread_getspecific(thread_error_key);
|
317 |
355 |
if ( previous )
|
318 |
356 |
free(previous);
|
319 |
|
|
|
357 |
|
320 |
358 |
pthread_setspecific(thread_error_key, strdup(error));
|
321 |
359 |
}
|
322 |
|
|
|
360 |
|
323 |
361 |
return 0;
|
324 |
362 |
}
|
325 |
363 |
|
326 |
364 |
|
327 |
365 |
|
328 |
366 |
const char *_prelude_thread_get_error(void)
|
329 |
|
{
|
|
367 |
{
|
330 |
368 |
if ( use_thread )
|
331 |
369 |
return pthread_getspecific(thread_error_key);
|
332 |
370 |
else
|