32#ifndef _RWSTD_RW_MUTEX_H_INCLUDED
33#define _RWSTD_RW_MUTEX_H_INCLUDED
37# pragma GCC system_header
41#ifndef _RWSTD_RW_DEFS_H_INCLUDED
46#ifndef _RWSTD_RW_ATOMIC_H_INCLUDED
51#ifdef _RWSTD_REENTRANT
53# ifndef _RWSTD_RW_EXCEPTION_H_INCLUDED
57# ifndef _RWSTD_RW_ERROR_H_INCLUDED
63# if defined (__SunOS_5_8) || defined (__SunOS_5_9)
67# if defined (_RWSTD_SOLARIS_THREADS)
69# elif defined (_RWSTD_POSIX_THREADS)
71# elif defined (_RWSTD_DCE_THREADS)
73# elif defined (_WIN32)
75# elif defined (__OS2__)
78# error unknown thread environment
82# if defined(_RWSTD_NO_STATIC_MUTEX_INIT)
96 __rw_thread_error ()
_THROWS (())
99 virtual const char* what () const
_THROWS (()) {
100 return "thread synchronization error";
113# if !defined (__HP_aCC) || __HP_aCC > 32700
116 "synchronization error");
125# ifdef _RWSTD_NO_STATIC_MUTEX_INIT
137 __rw_mutex_base (
const __rw_mutex_base&);
138 __rw_mutex_base& operator= (
const __rw_mutex_base&);
146inline void __rw_mutex_base::_C_release ()
160# ifndef _RWSTD_NO_STATIC_MUTEX_INIT
169 __rw_mutex (
const __rw_mutex&);
170 __rw_mutex& operator= (
const __rw_mutex&);
177# ifndef _RWSTD_NO_STATIC_MUTEX_INIT
183template <
class _TypeT>
184struct __rw_static_mutex
186 static __rw_mutex_base _C_mutex;
190template <
class _TypeT>
191__rw_mutex_base __rw_static_mutex<_TypeT>::_C_mutex
193# ifdef _RWSTD_MUTEX_INITIALIZER
197# undef _RWSTD_MUTEX_INITIALIZER
201# if _RWSTD_INSTANTIATE (_STATIC_MUTEX, _INT)
212inline __rw_mutex::__rw_mutex ()
216inline __rw_mutex_base::__rw_mutex_base ()
224# ifndef _RWSTD_NO_STATIC_MUTEX_INIT
226inline __rw_mutex::~__rw_mutex ()
230inline __rw_mutex_base::~__rw_mutex_base ()
238template<
class _TypeT,
int _IntI>
struct __rw_type { };
248# ifndef _RWSTD_NO_STATIC_MUTEX_INIT
250template <
class _TypeT>
252__rw_mutex_base& __rw_get_static_mutex (_TypeT*)
255 return __rw_static_mutex<_TypeT>::_C_mutex;
260# ifdef _INLINE_WITH_STATICS
262template <
class _TypeT>
264__rw_mutex_base& __rw_get_static_mutex (_TypeT*)
268template <
class _TypeT>
269__rw_mutex_base& __rw_get_static_mutex (_TypeT*)
277 union __mutex_buf_t {
279 char __buf [
sizeof (__rw_mutex_base)];
283 static __mutex_buf_t __mutex_buf;
286 __rw_mutex_base &__mutex =
296 static volatile int __cntr ;
298# if !defined (_RWSTD_NO_ATOMIC_OPS) && !defined (_RWSTD_NO_INT_ATOMIC_OPS)
306 if (0 == __cntr && 1 == ++__cntr)
311 new (&__mutex) __rw_mutex_base ();
319 while (__cntr < 1000);
328# undef _RWSTD_MUTEX_LOCK
329# undef _RWSTD_MUTEX_UNLOCK
330# undef _RWSTD_MUTEX_T
336 __rw_mutex_base *_C_mutex;
339 __rw_guard& operator= (
const __rw_guard&);
343 __rw_guard (__rw_guard &__rhs)
344 : _C_mutex (__rhs._C_mutex) {
348 __rw_guard (__rw_mutex_base &__mutex): _C_mutex (&__mutex) {
349 _C_mutex->_C_acquire ();
352 __rw_guard (__rw_mutex_base *__mutex): _C_mutex (__mutex) {
354 _C_mutex->_C_acquire ();
359 _C_mutex->_C_release ();
362 __rw_mutex_base* _C_set (__rw_mutex_base *__mutex) {
363 __rw_mutex_base *__tmp = _C_mutex;
364 return _C_mutex = __mutex, __tmp;
375 _C_mutex._C_acquire ();
379 _C_mutex._C_release ();
382 __rw_guard _C_guard () {
383 __rw_guard __guard (_C_mutex);
392# ifndef _RWSTD_RW_ATOMIC_MUTEX_H_INCLUDED
403struct __rw_mutex_base
405 void _C_acquire () { }
407 void _C_release () { }
418 __rw_guard (__rw_mutex_base&) { }
420 __rw_guard (__rw_mutex_base*) { }
422 __rw_mutex_base* _C_set (__rw_mutex_base*) {
428struct __rw_synchronized
435 void _C_unlock () { }
437 __rw_guard _C_guard () {
438 return __rw_guard (_C_mutex);
449#ifdef _RWSTD_NO_CHAR_ATOMIC_OPS
450# undef _RWSTD_NO_CHAR_ATOMIC_OPS
453#ifdef _RWSTD_NO_SHORT_ATOMIC_OPS
454# undef _RWSTD_NO_SHORT_ATOMIC_OPS
457#ifdef _RWSTD_NO_INT_ATOMIC_OPS
458# undef _RWSTD_NO_INT_ATOMIC_OPS
461#ifdef _RWSTD_NO_LONG_ATOMIC_OPS
462# undef _RWSTD_NO_LONG_ATOMIC_OPS
465#ifdef _RWSTD_NO_LLONG_ATOMIC_OPS
466# undef _RWSTD_NO_LLONG_ATOMIC_OPS
#define _INLINE_WITH_STATICS
#define _RWSTD_INSTANTIATE_1(arg)
#define _RWSTD_ATOMIC_PREINCREMENT(x, ignore)
#define _RWSTD_REINTERPRET_CAST(T, x)
#define _RWSTD_NAMESPACE(name)
#define _RWSTD_CONST_CAST(T, x)
#define _RWSTD_ERROR_RUNTIME_ERROR
#define _RWSTD_MUTEX_DESTROY(mutex)
#define _RWSTD_MUTEX_UNLOCK(mutex)
#define _RWSTD_MUTEX_INIT(mutex)
#define _RWSTD_MUTEX_LOCK(mutex)
#define _RWSTD_MUTEX_INITIALIZER