2 * Copyright (c) 1997-1999
3 * Silicon Graphics Computer Systems, Inc.
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
11 * Permission to use or copy this software for any purpose is hereby granted
12 * without fee, provided the above notices are retained on all copies.
13 * Permission to modify the code and to distribute modified code is granted,
14 * provided the above notices are retained, and a notice that the code was
15 * modified is included with the above copyright notice.
19 // WARNING: This is an internal header file, included by other C++
20 // standard library headers. You should not attempt to use this header
24 #ifndef _STLP_INTERNAL_THREADS_H
25 #define _STLP_INTERNAL_THREADS_H
27 // Supported threading models are native SGI, pthreads, uithreads
28 // (similar to pthreads, but based on an earlier draft of the Posix
29 // threads standard), and Win32 threads. Uithread support by Jochen
30 // Schlick, 1999, and Solaris threads generalized to them.
32 #ifndef _STLP_INTERNAL_CSTDDEF
33 # include <stl/_cstddef.h>
36 #ifndef _STLP_INTERNAL_CSTDLIB
37 # include <stl/_cstdlib.h>
40 // On SUN and Mac OS X gcc, zero-initialization works just fine...
41 #if defined (__sun) || (defined (__GNUC__) && defined(__APPLE__))
42 # define _STLP_MUTEX_INITIALIZER
45 /* This header defines the following atomic operation that platform should
46 * try to support as much as possible. Atomic operation are exposed as macro
47 * in order to easily test for their existance. They are:
48 * __stl_atomic_t _STLP_ATOMIC_INCREMENT(volatile __stl_atomic_t* __ptr) :
49 * increment *__ptr by 1 and returns the new value
50 * __stl_atomic_t _STLP_ATOMIC_DECREMENT(volatile __stl_atomic_t* __ptr) :
51 * decrement *__ptr by 1 and returns the new value
52 * __stl_atomic_t _STLP_ATOMIC_EXCHANGE(volatile __stl_atomic_t* __target, __stl_atomic_t __val) :
53 * assign __val to *__target and returns former *__target value
54 * void* _STLP_ATOMIC_EXCHANGE_PTR(void* volatile* __target, void* __ptr) :
55 * assign __ptr to *__target and returns former *__target value
56 * __stl_atomic_t _STLP_ATOMIC_ADD(volatile __stl_atomic_t* __target, __stl_atomic_t __val) :
57 * does *__target = *__target + __val and returns the old *__target value
60 #if defined (_STLP_WIN32) || defined (__sgi) || defined (_STLP_SPARC_SOLARIS_THREADS)
61 typedef long __stl_atomic_t;
63 /* Don't import whole namespace!!!! - ptr */
64 // # if defined (_STLP_USE_NAMESPACES) && ! defined (_STLP_VENDOR_GLOBAL_CSTD)
65 // // using _STLP_VENDOR_CSTD::size_t;
66 // using namespace _STLP_VENDOR_CSTD;
68 typedef size_t __stl_atomic_t;
71 #if defined (_STLP_THREADS)
73 # if defined (_STLP_SGI_THREADS)
76 // Hack for SGI o32 compilers.
77 # if !defined(__add_and_fetch) && \
78 (__mips < 3 || !(defined (_ABIN32) || defined(_ABI64)))
79 # define __add_and_fetch(__l,__v) add_then_test((unsigned long*)__l,__v)
80 # define __test_and_set(__l,__v) test_and_set(__l,__v)
83 # if __mips < 3 || !(defined (_ABIN32) || defined(_ABI64))
84 # define _STLP_ATOMIC_EXCHANGE(__p, __q) test_and_set(__p, __q)
86 # define _STLP_ATOMIC_EXCHANGE(__p, __q) __test_and_set((unsigned long*)__p, (unsigned long)__q)
89 # define _STLP_ATOMIC_INCREMENT(__x) __add_and_fetch(__x, 1)
90 # define _STLP_ATOMIC_DECREMENT(__x) __add_and_fetch(__x, (size_t) -1)
92 # elif defined (_STLP_PTHREADS)
95 # if !defined (_STLP_USE_PTHREAD_SPINLOCK)
96 # if defined (PTHREAD_MUTEX_INITIALIZER) && !defined (_STLP_MUTEX_INITIALIZER) && defined (_REENTRANT)
97 # define _STLP_MUTEX_INITIALIZER = { PTHREAD_MUTEX_INITIALIZER }
99 //HPUX variants have (on some platforms optional) non-standard "DCE" pthreads impl
100 # if defined (_DECTHREADS_) && (defined (_PTHREAD_USE_D4) || defined (__hpux)) && !defined (_CMA_SUPPRESS_EXTERNALS_)
101 # define _STLP_PTHREAD_ATTR_DEFAULT pthread_mutexattr_default
103 # define _STLP_PTHREAD_ATTR_DEFAULT 0
105 # else // _STLP_USE_PTHREAD_SPINLOCK
106 # if defined (__OpenBSD__)
107 # include <spinlock.h>
109 # endif // _STLP_USE_PTHREAD_SPINLOCK
111 # if defined (__GNUC__) && defined (__i386__)
113 # if !defined (_STLP_ATOMIC_INCREMENT)
114 inline long _STLP_atomic_increment_gcc_x86(long volatile* p) {
117 ("lock; xaddl %1, %0;"
118 :"=m" (*p), "=r" (result)
123 # define _STLP_ATOMIC_INCREMENT(__x) (_STLP_atomic_increment_gcc_x86((long volatile*)__x))
126 # if !defined (_STLP_ATOMIC_DECREMENT)
127 inline long _STLP_atomic_decrement_gcc_x86(long volatile* p) {
130 ("lock; xaddl %1, %0;"
131 :"=m" (*p), "=r" (result)
136 # define _STLP_ATOMIC_DECREMENT(__x) (_STLP_atomic_decrement_gcc_x86((long volatile*)__x))
139 # if !defined (_STLP_ATOMIC_ADD)
140 inline long _STLP_atomic_add_gcc_x86(long volatile* p, long addend) {
143 ("lock; xaddl %1, %0;"
144 :"=m" (*p), "=r" (result)
145 :"m" (*p), "1" (addend)
147 return result + addend;
149 # define _STLP_ATOMIC_ADD(__dst, __val) (_STLP_atomic_add_gcc_x86((long volatile*)__dst, (long)__val))
152 # endif /* if defined(__GNUC__) && defined(__i386__) */
154 # elif defined (_STLP_WIN32THREADS)
156 # if !defined (_STLP_ATOMIC_INCREMENT)
157 # if !defined (_STLP_NEW_PLATFORM_SDK)
158 # define _STLP_ATOMIC_INCREMENT(__x) InterlockedIncrement(__CONST_CAST(long*, __x))
159 # define _STLP_ATOMIC_DECREMENT(__x) InterlockedDecrement(__CONST_CAST(long*, __x))
160 # define _STLP_ATOMIC_EXCHANGE(__x, __y) InterlockedExchange(__CONST_CAST(long*, __x), __y)
162 # define _STLP_ATOMIC_INCREMENT(__x) InterlockedIncrement(__x)
163 # define _STLP_ATOMIC_DECREMENT(__x) InterlockedDecrement(__x)
164 # define _STLP_ATOMIC_EXCHANGE(__x, __y) InterlockedExchange(__x, __y)
166 # define _STLP_ATOMIC_EXCHANGE_PTR(__x, __y) STLPInterlockedExchangePointer(__x, __y)
168 * The following functionnality is only available since Windows 98, those that are targeting previous OSes
169 * should define _WIN32_WINDOWS to a value lower that the one of Win 98, see Platform SDK documentation for
172 # if defined (_STLP_NEW_PLATFORM_SDK) && (!defined (WINVER) || (WINVER >= 0x0410)) && \
173 (!defined (_WIN32_WINDOWS) || (_WIN32_WINDOWS >= 0x0410))
174 # define _STLP_ATOMIC_ADD(__dst, __val) InterlockedExchangeAdd(__dst, __val)
178 # elif defined (__DECC) || defined (__DECCXX)
180 # include <machine/builtins.h>
181 # define _STLP_ATOMIC_EXCHANGE __ATOMIC_EXCH_LONG
182 # define _STLP_ATOMIC_INCREMENT(__x) __ATOMIC_ADD_LONG(__x, 1)
183 # define _STLP_ATOMIC_DECREMENT(__x) __ATOMIC_ADD_LONG(__x, -1)
185 # elif defined(_STLP_SPARC_SOLARIS_THREADS)
187 # include <stl/_sparc_atomic.h>
189 # elif defined (_STLP_UITHREADS)
191 // this inclusion is potential hazard to bring up all sorts
192 // of old-style headers. Let's assume vendor already know how
193 // to deal with that.
194 # ifndef _STLP_INTERNAL_CTIME
195 # include <stl/_ctime.h>
197 # if defined (_STLP_USE_NAMESPACES) && ! defined (_STLP_VENDOR_GLOBAL_CSTD)
198 using _STLP_VENDOR_CSTD::time_t;
204 # elif defined (_STLP_BETHREADS)
209 # define _STLP_MUTEX_INITIALIZER = { 0 }
211 # elif defined (_STLP_NWTHREADS)
213 # include <nwthread.h>
214 # include <nwsemaph.h>
216 # elif defined(_STLP_OS2THREADS)
218 # if defined (__GNUC__)
219 # define INCL_DOSSEMAPHORES
222 // This section serves to replace os2.h for VisualAge C++
223 typedef unsigned long ULONG;
224 # if !defined (__HEV__) /* INCL_SEMAPHORE may also define HEV */
229 typedef ULONG APIRET;
232 typedef const char* PCSZ;
233 typedef ULONG BOOL32;
234 APIRET _System DosCreateMutexSem(PCSZ pszName, PHEV phev, ULONG flAttr, BOOL32 fState);
235 APIRET _System DosRequestMutexSem(HMTX hmtx, ULONG ulTimeout);
236 APIRET _System DosReleaseMutexSem(HMTX hmtx);
237 APIRET _System DosCloseMutexSem(HMTX hmtx);
238 # define _STLP_MUTEX_INITIALIZER = { 0 }
245 # define _STLP_ATOMIC_INCREMENT(__x) ++(*__x)
246 # define _STLP_ATOMIC_DECREMENT(__x) --(*__x)
247 /* We do not grant other atomic operations as they are useless if STLport do not have
252 #if !defined (_STLP_MUTEX_INITIALIZER)
253 # if defined(_STLP_ATOMIC_EXCHANGE)
254 # define _STLP_MUTEX_INITIALIZER = { 0 }
255 # elif defined(_STLP_UITHREADS)
256 # define _STLP_MUTEX_INITIALIZER = { DEFAULTMUTEX }
258 # define _STLP_MUTEX_INITIALIZER
262 _STLP_BEGIN_NAMESPACE
264 #if defined (_STLP_THREADS) && !defined (_STLP_USE_PTHREAD_SPINLOCK)
265 // Helper struct. This is a workaround for various compilers that don't
266 // handle static variables in inline functions properly.
267 template <int __inst>
268 struct _STLP_mutex_spin {
269 enum { __low_max = 30, __high_max = 1000 };
270 // Low if we suspect uniprocessor, high for multiprocessor.
271 static unsigned __max;
272 static unsigned __last;
273 static void _STLP_CALL _M_do_lock(volatile __stl_atomic_t* __lock);
274 static void _STLP_CALL _S_nsec_sleep(int __log_nsec);
276 #endif // !_STLP_USE_PTHREAD_SPINLOCK
278 // Locking class. Note that this class *does not have a constructor*.
279 // It must be initialized either statically, with _STLP_MUTEX_INITIALIZER,
280 // or dynamically, by explicitly calling the _M_initialize member function.
281 // (This is similar to the ways that a pthreads mutex can be initialized.)
282 // There are explicit member functions for acquiring and releasing the lock.
284 // There is no constructor because static initialization is essential for
285 // some uses, and only a class aggregate (see section 8.5.1 of the C++
286 // standard) can be initialized that way. That means we must have no
287 // constructors, no base classes, no virtual functions, and no private or
288 // protected members.
290 // For non-static cases, clients should use _STLP_mutex.
292 struct _STLP_CLASS_DECLSPEC _STLP_mutex_base {
293 #if defined (_STLP_ATOMIC_EXCHANGE) || defined (_STLP_SGI_THREADS)
294 // It should be relatively easy to get this to work on any modern Unix.
295 volatile __stl_atomic_t _M_lock;
298 #if defined (_STLP_THREADS)
299 # if defined (_STLP_ATOMIC_EXCHANGE)
300 inline void _M_initialize() { _M_lock = 0; }
301 inline void _M_destroy() {}
303 void _M_acquire_lock() {
304 _STLP_mutex_spin<0>::_M_do_lock(&_M_lock);
307 inline void _M_release_lock() {
308 volatile __stl_atomic_t* __lock = &_M_lock;
309 # if defined(_STLP_SGI_THREADS) && defined(__GNUC__) && __mips >= 3
312 # elif defined(_STLP_SGI_THREADS) && __mips >= 3 && \
313 (defined (_ABIN32) || defined(_ABI64))
314 __lock_release(__lock);
315 # elif defined (_STLP_SPARC_SOLARIS_THREADS)
316 # if defined (__WORD64) || defined (__arch64__) || defined (__sparcv9) || defined (__sparcv8plus)
317 asm("membar #StoreStore ; membar #LoadStore");
324 // This is not sufficient on many multiprocessors, since
325 // writes to protected variables and the lock may be reordered.
328 # elif defined (_STLP_PTHREADS)
329 # if defined (_STLP_USE_PTHREAD_SPINLOCK)
330 # if !defined (__OpenBSD__)
331 pthread_spinlock_t _M_lock;
332 inline void _M_initialize() { pthread_spin_init( &_M_lock, 0 ); }
333 inline void _M_destroy() { pthread_spin_destroy( &_M_lock ); }
335 // sorry, but no static initializer for pthread_spinlock_t;
336 // this will not work for compilers that has problems with call
337 // constructor of static object...
339 // _STLP_mutex_base()
340 // { pthread_spin_init( &_M_lock, 0 ); }
342 // ~_STLP_mutex_base()
343 // { pthread_spin_destroy( &_M_lock ); }
345 inline void _M_acquire_lock() { pthread_spin_lock( &_M_lock ); }
346 inline void _M_release_lock() { pthread_spin_unlock( &_M_lock ); }
347 # else // __OpenBSD__
349 inline void _M_initialize() { _SPINLOCK_INIT( &_M_lock ); }
350 inline void _M_destroy() { }
351 inline void _M_acquire_lock() { _SPINLOCK( &_M_lock ); }
352 inline void _M_release_lock() { _SPINUNLOCK( &_M_lock ); }
353 # endif // __OpenBSD__
354 # else // !_STLP_USE_PTHREAD_SPINLOCK
355 pthread_mutex_t _M_lock;
356 inline void _M_initialize()
357 { pthread_mutex_init(&_M_lock,_STLP_PTHREAD_ATTR_DEFAULT); }
358 inline void _M_destroy()
359 { pthread_mutex_destroy(&_M_lock); }
360 inline void _M_acquire_lock() {
361 # if defined ( __hpux ) && ! defined (PTHREAD_MUTEX_INITIALIZER)
362 if (!_M_lock.field1) _M_initialize();
364 pthread_mutex_lock(&_M_lock);
366 inline void _M_release_lock() { pthread_mutex_unlock(&_M_lock); }
367 # endif // !_STLP_USE_PTHREAD_SPINLOCK
369 # elif defined (_STLP_UITHREADS)
371 inline void _M_initialize()
372 { mutex_init(&_M_lock, 0, NULL); }
373 inline void _M_destroy()
374 { mutex_destroy(&_M_lock); }
375 inline void _M_acquire_lock() { mutex_lock(&_M_lock); }
376 inline void _M_release_lock() { mutex_unlock(&_M_lock); }
378 # elif defined (_STLP_OS2THREADS)
380 inline void _M_initialize() { DosCreateMutexSem(NULL, &_M_lock, 0, false); }
381 inline void _M_destroy() { DosCloseMutexSem(_M_lock); }
382 inline void _M_acquire_lock() {
383 if (!_M_lock) _M_initialize();
384 DosRequestMutexSem(_M_lock, SEM_INDEFINITE_WAIT);
386 inline void _M_release_lock() { DosReleaseMutexSem(_M_lock); }
387 # elif defined (_STLP_BETHREADS)
389 inline void _M_initialize() {
390 sem = create_sem(1, "STLPort");
393 inline void _M_destroy() {
394 int t = delete_sem(sem);
395 assert(t == B_NO_ERROR);
397 inline void _M_acquire_lock();
398 inline void _M_release_lock() {
399 status_t t = release_sem(sem);
400 assert(t == B_NO_ERROR);
402 # elif defined (_STLP_NWTHREADS)
404 inline void _M_initialize()
405 { _M_lock = OpenLocalSemaphore(1); }
406 inline void _M_destroy()
407 { CloseLocalSemaphore(_M_lock); }
408 inline void _M_acquire_lock()
409 { WaitOnLocalSemaphore(_M_lock); }
410 inline void _M_release_lock() { SignalLocalSemaphore(_M_lock); }
411 # else //*ty 11/24/2001 - added configuration check
412 # error "Unknown thread facility configuration"
414 #else /* No threads */
415 inline void _M_initialize() {}
416 inline void _M_destroy() {}
417 inline void _M_acquire_lock() {}
418 inline void _M_release_lock() {}
419 #endif // _STLP_PTHREADS
422 // Locking class. The constructor initializes the lock, the destructor destroys it.
423 // Well - behaving class, does not need static initializer
425 class _STLP_CLASS_DECLSPEC _STLP_mutex : public _STLP_mutex_base {
427 inline _STLP_mutex () { _M_initialize(); }
428 inline ~_STLP_mutex () { _M_destroy(); }
430 _STLP_mutex(const _STLP_mutex&);
431 void operator=(const _STLP_mutex&);
434 // A locking class that uses _STLP_STATIC_MUTEX. The constructor takes
435 // a reference to an _STLP_STATIC_MUTEX, and acquires a lock. The destructor
436 // releases the lock.
437 // It's not clear that this is exactly the right functionality.
438 // It will probably change in the future.
440 struct _STLP_CLASS_DECLSPEC _STLP_auto_lock {
441 _STLP_auto_lock(_STLP_STATIC_MUTEX& __lock) : _M_lock(__lock)
442 { _M_lock._M_acquire_lock(); }
444 { _M_lock._M_release_lock(); }
447 _STLP_STATIC_MUTEX& _M_lock;
448 void operator=(const _STLP_auto_lock&);
449 _STLP_auto_lock(const _STLP_auto_lock&);
453 * Class _Refcount_Base provides a type, __stl_atomic_t, a data member,
454 * _M_ref_count, and member functions _M_incr and _M_decr, which perform
455 * atomic preincrement/predecrement. The constructor initializes
458 class _STLP_CLASS_DECLSPEC _Refcount_Base {
459 // The data member _M_ref_count
460 #if defined (__DMC__)
463 _STLP_VOLATILE __stl_atomic_t _M_ref_count;
465 #if !defined (_STLP_ATOMIC_EXCHANGE)
466 _STLP_mutex _M_mutex;
471 _Refcount_Base(__stl_atomic_t __n) : _M_ref_count(__n) {}
473 // _M_incr and _M_decr
474 #if defined (_STLP_THREADS)
475 # if defined (_STLP_ATOMIC_EXCHANGE)
476 int _M_incr() { return _STLP_ATOMIC_INCREMENT(&_M_ref_count); }
477 int _M_decr() { return _STLP_ATOMIC_DECREMENT(&_M_ref_count); }
480 _STLP_auto_lock l(_M_mutex);
481 return ++_M_ref_count;
484 _STLP_auto_lock l(_M_mutex);
485 return --_M_ref_count;
488 #else /* No threads */
489 int _M_incr() { return ++_M_ref_count; }
490 int _M_decr() { return --_M_ref_count; }
494 /* Atomic swap on __stl_atomic_t
495 * This is guaranteed to behave as though it were atomic only if all
496 * possibly concurrent updates use _Atomic_swap.
497 * In some cases the operation is emulated with a lock.
498 * Idem for _Atomic_swap_ptr
500 /* Helper struct to handle following cases:
501 * - on platforms where sizeof(__stl_atomic_t) == sizeof(void*) atomic
502 * exchange can be done on pointers
503 * - on platform without atomic operation swap is done in a critical section,
504 * portable but inefficient.
506 template <int __use_ptr_atomic_swap>
507 class _Atomic_swap_struct {
509 #if defined (_STLP_THREADS) && \
510 !defined (_STLP_ATOMIC_EXCHANGE) && \
511 (defined (_STLP_PTHREADS) || defined (_STLP_UITHREADS) || defined (_STLP_OS2THREADS) || \
512 defined (_STLP_USE_PTHREAD_SPINLOCK) || defined (_STLP_NWTHREADS))
513 # define _STLP_USE_ATOMIC_SWAP_MUTEX
514 static _STLP_STATIC_MUTEX _S_swap_lock;
517 static __stl_atomic_t _S_swap(_STLP_VOLATILE __stl_atomic_t* __p, __stl_atomic_t __q) {
518 #if defined (_STLP_THREADS)
519 # if defined (_STLP_ATOMIC_EXCHANGE)
520 return _STLP_ATOMIC_EXCHANGE(__p, __q);
521 # elif defined (_STLP_USE_ATOMIC_SWAP_MUTEX)
522 _S_swap_lock._M_acquire_lock();
523 __stl_atomic_t __result = *__p;
525 _S_swap_lock._M_release_lock();
528 # error Missing atomic swap implementation
532 __stl_atomic_t __result = *__p;
535 #endif // _STLP_THREADS
538 static void* _S_swap_ptr(void* _STLP_VOLATILE* __p, void* __q) {
539 #if defined (_STLP_THREADS)
540 # if defined (_STLP_ATOMIC_EXCHANGE_PTR)
541 return _STLP_ATOMIC_EXCHANGE_PTR(__p, __q);
542 # elif defined (_STLP_ATOMIC_EXCHANGE)
543 _STLP_STATIC_ASSERT(sizeof(__stl_atomic_t) == sizeof(void*))
544 return __REINTERPRET_CAST(void*, _STLP_ATOMIC_EXCHANGE(__REINTERPRET_CAST(volatile __stl_atomic_t*, __p),
545 __REINTERPRET_CAST(__stl_atomic_t, __q));
546 # elif defined (_STLP_USE_ATOMIC_SWAP_MUTEX)
547 _S_swap_lock._M_acquire_lock();
548 void *__result = *__p;
550 _S_swap_lock._M_release_lock();
553 # error Missing pointer atomic swap implementation
557 void *__result = *__p;
565 class _Atomic_swap_struct<0> {
567 #if defined (_STLP_THREADS) && \
568 (!defined (_STLP_ATOMIC_EXCHANGE) || !defined (_STLP_ATOMIC_EXCHANGE_PTR)) && \
569 (defined (_STLP_PTHREADS) || defined (_STLP_UITHREADS) || defined (_STLP_OS2THREADS) || \
570 defined (_STLP_USE_PTHREAD_SPINLOCK) || defined (_STLP_NWTHREADS))
571 # define _STLP_USE_ATOMIC_SWAP_MUTEX
572 static _STLP_STATIC_MUTEX _S_swap_lock;
575 static __stl_atomic_t _S_swap(_STLP_VOLATILE __stl_atomic_t* __p, __stl_atomic_t __q) {
576 #if defined (_STLP_THREADS)
577 # if defined (_STLP_ATOMIC_EXCHANGE)
578 return _STLP_ATOMIC_EXCHANGE(__p, __q);
579 # elif defined (_STLP_USE_ATOMIC_SWAP_MUTEX)
580 /* This should be portable, but performance is expected
581 * to be quite awful. This really needs platform specific
584 _S_swap_lock._M_acquire_lock();
585 __stl_atomic_t __result = *__p;
587 _S_swap_lock._M_release_lock();
590 # error Missing atomic swap implementation
594 __stl_atomic_t __result = *__p;
597 #endif // _STLP_THREADS
600 static void* _S_swap_ptr(void* _STLP_VOLATILE* __p, void* __q) {
601 #if defined (_STLP_THREADS)
602 # if defined (_STLP_ATOMIC_EXCHANGE_PTR)
603 return _STLP_ATOMIC_EXCHANGE_PTR(__p, __q);
604 # elif defined (_STLP_USE_ATOMIC_SWAP_MUTEX)
605 _S_swap_lock._M_acquire_lock();
606 void *__result = *__p;
608 _S_swap_lock._M_release_lock();
611 # error Missing pointer atomic swap implementation
615 void *__result = *__p;
622 #if defined (_STLP_MSVC) && (_STLP_MSVC == 1300)
623 # pragma warning (push)
624 # pragma warning (disable : 4189) //__use_ptr_atomic_swap initialized but not used
627 inline __stl_atomic_t _STLP_CALL _Atomic_swap(_STLP_VOLATILE __stl_atomic_t * __p, __stl_atomic_t __q) {
628 const int __use_ptr_atomic_swap = sizeof(__stl_atomic_t) == sizeof(void*);
629 return _Atomic_swap_struct<__use_ptr_atomic_swap>::_S_swap(__p, __q);
632 inline void* _STLP_CALL _Atomic_swap_ptr(void* _STLP_VOLATILE* __p, void* __q) {
633 const int __use_ptr_atomic_swap = sizeof(__stl_atomic_t) == sizeof(void*);
634 return _Atomic_swap_struct<__use_ptr_atomic_swap>::_S_swap_ptr(__p, __q);
637 #if defined (_STLP_MSVC) && (_STLP_MSVC == 1300)
638 # pragma warning (pop)
641 #if defined (_STLP_BETHREADS)
642 template <int __inst>
643 struct _STLP_beos_static_lock_data {
645 struct mutex_t : public _STLP_mutex {
647 { _STLP_beos_static_lock_data<0>::is_init = true; }
649 { _STLP_beos_static_lock_data<0>::is_init = false; }
654 template <int __inst>
655 bool _STLP_beos_static_lock_data<__inst>::is_init = false;
656 template <int __inst>
657 typename _STLP_beos_static_lock_data<__inst>::mutex_t _STLP_beos_static_lock_data<__inst>::mut;
659 inline void _STLP_mutex_base::_M_acquire_lock() {
661 // we need to initialise on demand here
662 // to prevent race conditions use our global
663 // mutex if it's available:
664 if (_STLP_beos_static_lock_data<0>::is_init) {
665 _STLP_auto_lock al(_STLP_beos_static_lock_data<0>::mut);
666 if (sem == 0) _M_initialize();
669 // no lock available, we must still be
670 // in startup code, THERE MUST BE ONE THREAD
671 // ONLY active at this point.
676 t = acquire_sem(sem);
677 assert(t == B_NO_ERROR);
683 #if !defined (_STLP_LINK_TIME_INSTANTIATION)
684 # include <stl/_threads.c>
687 #endif /* _STLP_INTERNAL_THREADS_H */