gccxml_gem 0.9.1-x86-darwin-9 → 0.9.2-x86-darwin-9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,664 @@
1
+ /* Threads compatibility routines for libgcc2 and libobjc. */
2
+ /* Compile this one with gcc. */
3
+ /* Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003
4
+ Free Software Foundation, Inc.
5
+
6
+ This file is part of GCC.
7
+
8
+ GCC is free software; you can redistribute it and/or modify it under
9
+ the terms of the GNU General Public License as published by the Free
10
+ Software Foundation; either version 2, or (at your option) any later
11
+ version.
12
+
13
+ GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16
+ for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with GCC; see the file COPYING. If not, write to the Free
20
+ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21
+ 02111-1307, USA. */
22
+
23
+ /* As a special exception, if you link this library with other files,
24
+ some of which are compiled with GCC, to produce an executable,
25
+ this library does not by itself cause the resulting executable
26
+ to be covered by the GNU General Public License.
27
+ This exception does not however invalidate any other reasons why
28
+ the executable file might be covered by the GNU General Public License. */
29
+
30
+ #ifndef _GLIBCXX_GCC_GTHR_POSIX_H
31
+ #define _GLIBCXX_GCC_GTHR_POSIX_H
32
+
33
+ /* POSIX threads specific definitions.
34
+ Easy, since the interface is just one-to-one mapping. */
35
+
36
+ #define __GTHREADS 1
37
+
38
+ /* Some implementations of <pthread.h> require this to be defined. */
39
+ #if !defined(_REENTRANT) && defined(__osf__)
40
+ #define _REENTRANT 1
41
+ #endif
42
+
43
+ #include <pthread.h>
44
+ #include <unistd.h>
45
+
46
+ typedef pthread_key_t __gthread_key_t;
47
+ typedef pthread_once_t __gthread_once_t;
48
+ typedef pthread_mutex_t __gthread_mutex_t;
49
+ typedef pthread_mutex_t __gthread_recursive_mutex_t;
50
+
51
+ #define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
52
+ #define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
53
+ #if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
54
+ #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
55
+ #elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
56
+ #define __GTHREAD_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
57
+ #else
58
+ #define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
59
+ #endif
60
+
61
+ #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK && defined __GNUC_RH_RELEASE__ \
62
+ && ((__GNUC__ == 3 && __GNUC_MINOR__ == 4 && (__GNUC_PATCHLEVEL__ > 4 || (__GNUC_PATCHLEVEL__ == 4 && __GNUC_RH_RELEASE__ > 2))) \
63
+ || (__GNUC__ == 4 && __GNUC_MINOR__ == 0 && (__GNUC_PATCHLEVEL__ > 2 || (__GNUC_PATCHLEVEL__ == 2 && __GNUC_RH_RELEASE__ > 6)))) \
64
+ && ! defined __attribute__
65
+ # define __gthrw(name) \
66
+ extern __typeof(name) __gthrw_ ## name
67
+
68
+
69
+ __gthrw(pthread_once);
70
+ __gthrw(pthread_key_create);
71
+ __gthrw(pthread_key_delete);
72
+ __gthrw(pthread_getspecific);
73
+ __gthrw(pthread_setspecific);
74
+ __gthrw(pthread_create);
75
+
76
+ __gthrw(pthread_mutex_lock);
77
+ __gthrw(pthread_mutex_trylock);
78
+ __gthrw(pthread_mutex_unlock);
79
+ __gthrw(pthread_mutexattr_init);
80
+ __gthrw(pthread_mutexattr_settype);
81
+ __gthrw(pthread_mutexattr_destroy);
82
+
83
+ __gthrw(pthread_mutex_init);
84
+
85
+ # if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)
86
+ /* Objective-C. */
87
+ __gthrw(pthread_cond_broadcast);
88
+ __gthrw(pthread_cond_destroy);
89
+ __gthrw(pthread_cond_init);
90
+ __gthrw(pthread_cond_signal);
91
+ __gthrw(pthread_cond_wait);
92
+ __gthrw(pthread_exit);
93
+ __gthrw(pthread_mutex_destroy);
94
+ __gthrw(pthread_self);
95
+ /* These really should be protected by _POSIX_PRIORITY_SCHEDULING, but
96
+ we use them inside a _POSIX_THREAD_PRIORITY_SCHEDULING block. */
97
+ # ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
98
+ __gthrw(sched_get_priority_max);
99
+ __gthrw(sched_get_priority_min);
100
+ # endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
101
+ __gthrw(sched_yield);
102
+ __gthrw(pthread_attr_destroy);
103
+ __gthrw(pthread_attr_init);
104
+ __gthrw(pthread_attr_setdetachstate);
105
+ # ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
106
+ __gthrw(pthread_getschedparam);
107
+ __gthrw(pthread_setschedparam);
108
+ # endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
109
+ # endif /* _LIBOBJC || _LIBOBJC_WEAK */
110
+ #else
111
+ # if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
112
+ #pragma weak pthread_once
113
+ #pragma weak pthread_key_create
114
+ #pragma weak pthread_key_delete
115
+ #pragma weak pthread_getspecific
116
+ #pragma weak pthread_setspecific
117
+ #pragma weak pthread_create
118
+
119
+ #pragma weak pthread_mutex_lock
120
+ #pragma weak pthread_mutex_trylock
121
+ #pragma weak pthread_mutex_unlock
122
+ #pragma weak pthread_mutexattr_init
123
+ #pragma weak pthread_mutexattr_settype
124
+ #pragma weak pthread_mutexattr_destroy
125
+
126
+ #pragma weak pthread_mutex_init
127
+
128
+ #if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)
129
+ /* Objective-C. */
130
+ #pragma weak pthread_cond_broadcast
131
+ #pragma weak pthread_cond_destroy
132
+ #pragma weak pthread_cond_init
133
+ #pragma weak pthread_cond_signal
134
+ #pragma weak pthread_cond_wait
135
+ #pragma weak pthread_exit
136
+ #pragma weak pthread_mutex_destroy
137
+ #pragma weak pthread_self
138
+ /* These really should be protected by _POSIX_PRIORITY_SCHEDULING, but
139
+ we use them inside a _POSIX_THREAD_PRIORITY_SCHEDULING block. */
140
+ #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
141
+ #pragma weak sched_get_priority_max
142
+ #pragma weak sched_get_priority_min
143
+ #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
144
+ #pragma weak sched_yield
145
+ #pragma weak pthread_attr_destroy
146
+ #pragma weak pthread_attr_init
147
+ #pragma weak pthread_attr_setdetachstate
148
+ #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
149
+ #pragma weak pthread_getschedparam
150
+ #pragma weak pthread_setschedparam
151
+ #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
152
+ #endif /* _LIBOBJC || _LIBOBJC_WEAK */
153
+ #endif /* __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK */
154
+
155
+ #define __gthrw_pthread_once pthread_once
156
+ #define __gthrw_pthread_key_create pthread_key_create
157
+ #define __gthrw_pthread_key_delete pthread_key_delete
158
+ #define __gthrw_pthread_getspecific pthread_getspecific
159
+ #define __gthrw_pthread_setspecific pthread_setspecific
160
+ #define __gthrw_pthread_create pthread_create
161
+
162
+ #define __gthrw_pthread_mutex_lock pthread_mutex_lock
163
+ #define __gthrw_pthread_mutex_trylock pthread_mutex_trylock
164
+ #define __gthrw_pthread_mutex_unlock pthread_mutex_unlock
165
+ #define __gthrw_pthread_mutexattr_init pthread_mutexattr_init
166
+ #define __gthrw_pthread_mutexattr_settype pthread_mutexattr_settype
167
+ #define __gthrw_pthread_mutexattr_destroy pthread_mutexattr_destroy
168
+
169
+ #define __gthrw_pthread_mutex_init pthread_mutex_init
170
+
171
+ #if defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)
172
+ /* Objective-C. */
173
+ #define __gthrw_pthread_cond_broadcast pthread_cond_broadcast
174
+ #define __gthrw_pthread_cond_destroy pthread_cond_destroy
175
+ #define __gthrw_pthread_cond_init pthread_cond_init
176
+ #define __gthrw_pthread_cond_signal pthread_cond_signal
177
+ #define __gthrw_pthread_cond_wait pthread_cond_wait
178
+ #define __gthrw_pthread_exit pthread_exit
179
+ #define __gthrw_pthread_mutex_destroy pthread_mutex_destroy
180
+ #define __gthrw_pthread_self pthread_self
181
+ /* These really should be protected by _POSIX_PRIORITY_SCHEDULING, but
182
+ we use them inside a _POSIX_THREAD_PRIORITY_SCHEDULING block. */
183
+ #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
184
+ #define __gthrw_sched_get_priority_max sched_get_priority_max
185
+ #define __gthrw_sched_get_priority_min sched_get_priority_min
186
+ #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
187
+ #define __gthrw_sched_yield sched_yield
188
+ #define __gthrw_pthread_attr_destroy pthread_attr_destroy
189
+ #define __gthrw_pthread_attr_init pthread_attr_init
190
+ #define __gthrw_pthread_attr_setdetachstate pthread_attr_setdetachstate
191
+ #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
192
+ #define __gthrw_pthread_getschedparam pthread_getschedparam
193
+ #define __gthrw_pthread_setschedparam pthread_setschedparam
194
+ #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
195
+ #endif /* _LIBOBJC || _LIBOBJC_WEAK */
196
+ #endif
197
+
198
+
199
+ #if __GXX_WEAK__ && _GLIBCXX_GTHREAD_USE_WEAK
200
+
201
+ static inline int
202
+ __gthread_active_p (void)
203
+ {
204
+ static void *const __gthread_active_ptr = (void *) &__gthrw_pthread_create;
205
+ return __gthread_active_ptr != 0;
206
+ }
207
+
208
+ #else /* not __GXX_WEAK__ */
209
+
210
+ static inline int
211
+ __gthread_active_p (void)
212
+ {
213
+ return 1;
214
+ }
215
+
216
+ #endif /* __GXX_WEAK__ */
217
+
218
+ #ifdef _LIBOBJC
219
+
220
+ /* This is the config.h file in libobjc/ */
221
+ #include <config.h>
222
+
223
+ #ifdef HAVE_SCHED_H
224
+ # include <sched.h>
225
+ #endif
226
+
227
+ /* Key structure for maintaining thread specific storage */
228
+ static pthread_key_t _objc_thread_storage;
229
+ static pthread_attr_t _objc_thread_attribs;
230
+
231
+ /* Thread local storage for a single thread */
232
+ static void *thread_local_storage = NULL;
233
+
234
+ /* Backend initialization functions */
235
+
236
+ /* Initialize the threads subsystem. */
237
+ static inline int
238
+ __gthread_objc_init_thread_system (void)
239
+ {
240
+ if (__gthread_active_p ())
241
+ {
242
+ /* Initialize the thread storage key */
243
+ if (__gthrw_pthread_key_create (&_objc_thread_storage, NULL) == 0)
244
+ {
245
+ /* The normal default detach state for threads is
246
+ * PTHREAD_CREATE_JOINABLE which causes threads to not die
247
+ * when you think they should. */
248
+ if (__gthrw_pthread_attr_init (&_objc_thread_attribs) == 0
249
+ && __gthrw_pthread_attr_setdetachstate (&_objc_thread_attribs,
250
+ PTHREAD_CREATE_DETACHED) == 0)
251
+ return 0;
252
+ }
253
+ }
254
+
255
+ return -1;
256
+ }
257
+
258
+ /* Close the threads subsystem. */
259
+ static inline int
260
+ __gthread_objc_close_thread_system (void)
261
+ {
262
+ if (__gthread_active_p ()
263
+ && __gthrw_pthread_key_delete (_objc_thread_storage) == 0
264
+ && __gthrw_pthread_attr_destroy (&_objc_thread_attribs) == 0)
265
+ return 0;
266
+
267
+ return -1;
268
+ }
269
+
270
+ /* Backend thread functions */
271
+
272
+ /* Create a new thread of execution. */
273
+ static inline objc_thread_t
274
+ __gthread_objc_thread_detach (void (*func)(void *), void *arg)
275
+ {
276
+ objc_thread_t thread_id;
277
+ pthread_t new_thread_handle;
278
+
279
+ if (!__gthread_active_p ())
280
+ return NULL;
281
+
282
+ if (!(__gthrw_pthread_create (&new_thread_handle, NULL, (void *) func, arg)))
283
+ thread_id = (objc_thread_t) new_thread_handle;
284
+ else
285
+ thread_id = NULL;
286
+
287
+ return thread_id;
288
+ }
289
+
290
+ /* Set the current thread's priority. */
291
+ static inline int
292
+ __gthread_objc_thread_set_priority (int priority)
293
+ {
294
+ if (!__gthread_active_p ())
295
+ return -1;
296
+ else
297
+ {
298
+ #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
299
+ pthread_t thread_id = __gthrw_pthread_self ();
300
+ int policy;
301
+ struct sched_param params;
302
+ int priority_min, priority_max;
303
+
304
+ if (__gthrw_pthread_getschedparam (thread_id, &policy, &params) == 0)
305
+ {
306
+ if ((priority_max = __gthrw_sched_get_priority_max (policy)) == -1)
307
+ return -1;
308
+
309
+ if ((priority_min = __gthrw_sched_get_priority_min (policy)) == -1)
310
+ return -1;
311
+
312
+ if (priority > priority_max)
313
+ priority = priority_max;
314
+ else if (priority < priority_min)
315
+ priority = priority_min;
316
+ params.sched_priority = priority;
317
+
318
+ /*
319
+ * The solaris 7 and several other man pages incorrectly state that
320
+ * this should be a pointer to policy but pthread.h is universally
321
+ * at odds with this.
322
+ */
323
+ if (__gthrw_pthread_setschedparam (thread_id, policy, &params) == 0)
324
+ return 0;
325
+ }
326
+ #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
327
+ return -1;
328
+ }
329
+ }
330
+
331
+ /* Return the current thread's priority. */
332
+ static inline int
333
+ __gthread_objc_thread_get_priority (void)
334
+ {
335
+ #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING
336
+ if (__gthread_active_p ())
337
+ {
338
+ int policy;
339
+ struct sched_param params;
340
+
341
+ if (__gthrw_pthread_getschedparam (__gthrw_pthread_self (), &policy, &params) == 0)
342
+ return params.sched_priority;
343
+ else
344
+ return -1;
345
+ }
346
+ else
347
+ #endif /* _POSIX_THREAD_PRIORITY_SCHEDULING */
348
+ return OBJC_THREAD_INTERACTIVE_PRIORITY;
349
+ }
350
+
351
+ /* Yield our process time to another thread. */
352
+ static inline void
353
+ __gthread_objc_thread_yield (void)
354
+ {
355
+ if (__gthread_active_p ())
356
+ __gthrw_sched_yield ();
357
+ }
358
+
359
+ /* Terminate the current thread. */
360
+ static inline int
361
+ __gthread_objc_thread_exit (void)
362
+ {
363
+ if (__gthread_active_p ())
364
+ /* exit the thread */
365
+ __gthrw_pthread_exit (&__objc_thread_exit_status);
366
+
367
+ /* Failed if we reached here */
368
+ return -1;
369
+ }
370
+
371
+ /* Returns an integer value which uniquely describes a thread. */
372
+ static inline objc_thread_t
373
+ __gthread_objc_thread_id (void)
374
+ {
375
+ if (__gthread_active_p ())
376
+ return (objc_thread_t) __gthrw_pthread_self ();
377
+ else
378
+ return (objc_thread_t) 1;
379
+ }
380
+
381
+ /* Sets the thread's local storage pointer. */
382
+ static inline int
383
+ __gthread_objc_thread_set_data (void *value)
384
+ {
385
+ if (__gthread_active_p ())
386
+ return __gthrw_pthread_setspecific (_objc_thread_storage, value);
387
+ else
388
+ {
389
+ thread_local_storage = value;
390
+ return 0;
391
+ }
392
+ }
393
+
394
+ /* Returns the thread's local storage pointer. */
395
+ static inline void *
396
+ __gthread_objc_thread_get_data (void)
397
+ {
398
+ if (__gthread_active_p ())
399
+ return __gthrw_pthread_getspecific (_objc_thread_storage);
400
+ else
401
+ return thread_local_storage;
402
+ }
403
+
404
+ /* Backend mutex functions */
405
+
406
+ /* Allocate a mutex. */
407
+ static inline int
408
+ __gthread_objc_mutex_allocate (objc_mutex_t mutex)
409
+ {
410
+ if (__gthread_active_p ())
411
+ {
412
+ mutex->backend = objc_malloc (sizeof (pthread_mutex_t));
413
+
414
+ if (__gthrw_pthread_mutex_init ((pthread_mutex_t *) mutex->backend, NULL))
415
+ {
416
+ objc_free (mutex->backend);
417
+ mutex->backend = NULL;
418
+ return -1;
419
+ }
420
+ }
421
+
422
+ return 0;
423
+ }
424
+
425
+ /* Deallocate a mutex. */
426
+ static inline int
427
+ __gthread_objc_mutex_deallocate (objc_mutex_t mutex)
428
+ {
429
+ if (__gthread_active_p ())
430
+ {
431
+ int count;
432
+
433
+ /*
434
+ * Posix Threads specifically require that the thread be unlocked
435
+ * for __gthrw_pthread_mutex_destroy to work.
436
+ */
437
+
438
+ do
439
+ {
440
+ count = __gthrw_pthread_mutex_unlock ((pthread_mutex_t *) mutex->backend);
441
+ if (count < 0)
442
+ return -1;
443
+ }
444
+ while (count);
445
+
446
+ if (__gthrw_pthread_mutex_destroy ((pthread_mutex_t *) mutex->backend))
447
+ return -1;
448
+
449
+ objc_free (mutex->backend);
450
+ mutex->backend = NULL;
451
+ }
452
+ return 0;
453
+ }
454
+
455
+ /* Grab a lock on a mutex. */
456
+ static inline int
457
+ __gthread_objc_mutex_lock (objc_mutex_t mutex)
458
+ {
459
+ if (__gthread_active_p ()
460
+ && __gthrw_pthread_mutex_lock ((pthread_mutex_t *) mutex->backend) != 0)
461
+ {
462
+ return -1;
463
+ }
464
+
465
+ return 0;
466
+ }
467
+
468
+ /* Try to grab a lock on a mutex. */
469
+ static inline int
470
+ __gthread_objc_mutex_trylock (objc_mutex_t mutex)
471
+ {
472
+ if (__gthread_active_p ()
473
+ && __gthrw_pthread_mutex_trylock ((pthread_mutex_t *) mutex->backend) != 0)
474
+ {
475
+ return -1;
476
+ }
477
+
478
+ return 0;
479
+ }
480
+
481
+ /* Unlock the mutex */
482
+ static inline int
483
+ __gthread_objc_mutex_unlock (objc_mutex_t mutex)
484
+ {
485
+ if (__gthread_active_p ()
486
+ && __gthrw_pthread_mutex_unlock ((pthread_mutex_t *) mutex->backend) != 0)
487
+ {
488
+ return -1;
489
+ }
490
+
491
+ return 0;
492
+ }
493
+
494
+ /* Backend condition mutex functions */
495
+
496
+ /* Allocate a condition. */
497
+ static inline int
498
+ __gthread_objc_condition_allocate (objc_condition_t condition)
499
+ {
500
+ if (__gthread_active_p ())
501
+ {
502
+ condition->backend = objc_malloc (sizeof (pthread_cond_t));
503
+
504
+ if (__gthrw_pthread_cond_init ((pthread_cond_t *) condition->backend, NULL))
505
+ {
506
+ objc_free (condition->backend);
507
+ condition->backend = NULL;
508
+ return -1;
509
+ }
510
+ }
511
+
512
+ return 0;
513
+ }
514
+
515
+ /* Deallocate a condition. */
516
+ static inline int
517
+ __gthread_objc_condition_deallocate (objc_condition_t condition)
518
+ {
519
+ if (__gthread_active_p ())
520
+ {
521
+ if (__gthrw_pthread_cond_destroy ((pthread_cond_t *) condition->backend))
522
+ return -1;
523
+
524
+ objc_free (condition->backend);
525
+ condition->backend = NULL;
526
+ }
527
+ return 0;
528
+ }
529
+
530
+ /* Wait on the condition */
531
+ static inline int
532
+ __gthread_objc_condition_wait (objc_condition_t condition, objc_mutex_t mutex)
533
+ {
534
+ if (__gthread_active_p ())
535
+ return __gthrw_pthread_cond_wait ((pthread_cond_t *) condition->backend,
536
+ (pthread_mutex_t *) mutex->backend);
537
+ else
538
+ return 0;
539
+ }
540
+
541
+ /* Wake up all threads waiting on this condition. */
542
+ static inline int
543
+ __gthread_objc_condition_broadcast (objc_condition_t condition)
544
+ {
545
+ if (__gthread_active_p ())
546
+ return __gthrw_pthread_cond_broadcast ((pthread_cond_t *) condition->backend);
547
+ else
548
+ return 0;
549
+ }
550
+
551
+ /* Wake up one thread waiting on this condition. */
552
+ static inline int
553
+ __gthread_objc_condition_signal (objc_condition_t condition)
554
+ {
555
+ if (__gthread_active_p ())
556
+ return __gthrw_pthread_cond_signal ((pthread_cond_t *) condition->backend);
557
+ else
558
+ return 0;
559
+ }
560
+
561
+ #else /* _LIBOBJC */
562
+
563
+ static inline int
564
+ __gthread_once (__gthread_once_t *once, void (*func) (void))
565
+ {
566
+ if (__gthread_active_p ())
567
+ return __gthrw_pthread_once (once, func);
568
+ else
569
+ return -1;
570
+ }
571
+
572
+ static inline int
573
+ __gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
574
+ {
575
+ return __gthrw_pthread_key_create (key, dtor);
576
+ }
577
+
578
+ static inline int
579
+ __gthread_key_delete (__gthread_key_t key)
580
+ {
581
+ return __gthrw_pthread_key_delete (key);
582
+ }
583
+
584
+ static inline void *
585
+ __gthread_getspecific (__gthread_key_t key)
586
+ {
587
+ return __gthrw_pthread_getspecific (key);
588
+ }
589
+
590
+ static inline int
591
+ __gthread_setspecific (__gthread_key_t key, const void *ptr)
592
+ {
593
+ return __gthrw_pthread_setspecific (key, ptr);
594
+ }
595
+
596
+ static inline int
597
+ __gthread_mutex_lock (__gthread_mutex_t *mutex)
598
+ {
599
+ if (__gthread_active_p ())
600
+ return __gthrw_pthread_mutex_lock (mutex);
601
+ else
602
+ return 0;
603
+ }
604
+
605
+ static inline int
606
+ __gthread_mutex_trylock (__gthread_mutex_t *mutex)
607
+ {
608
+ if (__gthread_active_p ())
609
+ return __gthrw_pthread_mutex_trylock (mutex);
610
+ else
611
+ return 0;
612
+ }
613
+
614
+ static inline int
615
+ __gthread_mutex_unlock (__gthread_mutex_t *mutex)
616
+ {
617
+ if (__gthread_active_p ())
618
+ return __gthrw_pthread_mutex_unlock (mutex);
619
+ else
620
+ return 0;
621
+ }
622
+
623
+ #ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
624
+ static inline int
625
+ __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *mutex)
626
+ {
627
+ if (__gthread_active_p ())
628
+ {
629
+ pthread_mutexattr_t attr;
630
+ int r;
631
+
632
+ r = __gthrw_pthread_mutexattr_init (&attr);
633
+ if (!r)
634
+ r = __gthrw_pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
635
+ if (!r)
636
+ r = __gthrw_pthread_mutex_init (mutex, &attr);
637
+ if (!r)
638
+ r = __gthrw_pthread_mutexattr_destroy (&attr);
639
+ return r;
640
+ }
641
+ }
642
+ #endif
643
+
644
+ static inline int
645
+ __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
646
+ {
647
+ return __gthread_mutex_lock (mutex);
648
+ }
649
+
650
+ static inline int
651
+ __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
652
+ {
653
+ return __gthread_mutex_trylock (mutex);
654
+ }
655
+
656
+ static inline int
657
+ __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
658
+ {
659
+ return __gthread_mutex_unlock (mutex);
660
+ }
661
+
662
+ #endif /* _LIBOBJC */
663
+
664
+ #endif /* ! _GLIBCXX_GCC_GTHR_POSIX_H */