2008-10-13  Farid Zaripov  <faridz@apache.org>

	Merged revs 696275, 696295, 697875, 697883, 700495, 700810, 700888,
	701135, 702179, 702195, 702931, 703124, 703216 from 4.2.x branch.


	2008-09-17  Farid Zaripov  <faridz@apache.org>
	* src/random.cpp: #included <stddef.h> for size_t type.


	2008-09-17  Farid Zaripov  <faridz@apache.org>
	STDCXX-563
	* include/rw/_atomic-deccxx.h: New header file with definitions of
	inline functions for atomic operations on ALPHA platform.
	* include/rw/_atomic-mipspro.h: New header file with definitions of
	inline functions for atomic operations on MIPS platform.
	* include/rw/_atomic-mutex.h: New header file with definitions of
	inline functions for atomic operations with using mutex object.
	* include/rw/_atomic-parisc.h: New header file with definitions of
	inline functions for atomic operations on PA RISC platform.
	* include/rw/_atomic-sparc.h: New header file with definitions of
	inline functions for atomic operations on SPARC platform.
	* include/rw/_atomic-x64.h: New header file with definitions of inline
	functions for atomic operations on Intel IA64 and x64 platforms.
	* include/rw/_atomic-x86.h: New header file with definitions of inline
	functions for atomic operations on Intel x86 platform.
	* include/rw/_atomic-xlc.h: New header file with definitions of inline
	functions for atomic operations on POWERPC platform.
	* include/rw/_atomic.h: New header file with definitions of inline
	functions for atomic operations.
	* include/rw/_mutex-dce.h: New header file with definitions of classes
	for thread safety using DCE threads.
	* include/rw/_mutex-os2.h: New header file with definitions of classes
	for thread safety using OS2 threads.
	* include/rw/_mutex-pthread.h: New header file with definitions of
	classes for thread safety using POSIX threads.
	* include/rw/_mutex-solaris.h: New header file with definitions of
	classes for thread safety using Solaris threads.
	* include/rw/_mutex-win32.h: New header file with definitions of
	classes for thread safety using Windows threads.
	* include/rw/_mutex.h: Split content of the file to the set of
	platform specific and OS specific headers above.
	(__rw_get_static_mutex) [!_RWSTD_NO_ATOMIC_OPS && !_PA_RISC2_0]: Use
	_RWSTD_ATOMIC_PREINCREMENT() on all platforms where atomic increment is
	available instead of using _InterlockedIncrement() only on Windows.
	* src/i86: Directory renamed to src/x86 for consistency.
	* src/i86_64: Directory renamed to src/x86_64 for consistency.
	* src/atomic.asm: Renamed i86 to x86 and i86_64 to x86_64 respectively.
	* src/atomic.s: Ditto.
	* src/x86/atomic.inc: Ditto.
	* src/x86/atomic.s: Ditto.
	* src/x86_64/atomic.inc: Ditto.
	* src/x86_64/atomic.s: Ditto.


	2008-09-22  Farid Zaripov  <faridz@apache.org>
	STDCXX-455
	* util/ctype.cpp (process_ctype): Don't create symlink on Cygwin.
	(write_ctype): Same.
	* util/localedef.cpp (create_locale): Same.
	* util/path.cpp (create_symlink): Don't define function on Cygwin.


	2008-09-22  Farid Zaripov  <faridz@apache.org>
	* tests/containers/23.list.erase.cpp (test_erase): Simplify type of the pres_iter.


	2008-09-30  Farid Zaripov  <faridz@apache.org>
	* include/rw/_atomic-x86.h [!_MSC_VER && _RWSTD_INTERLOCKED_T]:
	Moved closing brace of the extern "C" block to the proper location.


	2008-10-01  Farid Zaripov  <faridz@apache.org>
	* include/rw/_atomic-deccxx.h: Correct $Id: line.
	* include/rw/_atomic-mipspro.h: Same.
	* include/rw/_atomic-mutex.h: Same.
	* include/rw/_atomic-parisc.h: Same.
	* include/rw/_atomic-sparc.h: Same.
	* include/rw/_atomic-x64.h: Same.
	* include/rw/_atomic-x86.h: Same.
	* include/rw/_atomic-xlc.h: Same.
	* include/rw/_atomic.h: Same.
	* include/rw/_mutex-dce.h: Same.
	* include/rw/_mutex-os2.h: Same.
	* include/rw/_mutex-pthread.h: Same.
	* include/rw/_mutex-solaris.h: Same.
	* include/rw/_mutex-win32.h: Same.
	* tests/include/rw_containers.h: Same.
	* tests/include/rw_lists.h: Same.
	* tests/src/23.containers.cpp: Same.


	2008-10-01  Farid Zaripov  <faridz@apache.org>
	* include/rw/_atomic-mutex.h: Make _RWSTD_RW_MUTEX_H_INCLUDED
	after #endif directive as comment to fix compile error.


	2008-10-02  Farid Zaripov  <faridz@apache.org>
	* include/rw/_atomic-sync.h: New header file with definitions
	of inline functions for atomic operations using __sync_xxx()
	built-in functions set.
	* include/rw/_atomic.h: #include <rw/_atomic-sync.h> with
	gcc >= 4.1 on x86, x86_64, ia64 platforms and icc on ia64 platform.


	2008-10-06  Farid Zaripov  <faridz@apache.org>
	* include/rw/_atomic-deccxx.h: #define corresponding
	_RWSTD_NO_XXX_ATOMIC_OPS macros for types, which are
	not supported in atomic operations.
	* include/rw/_atomic-mipspro.h: Ditto.
	* include/rw/_atomic-parisc.h: Ditto.
	* include/rw/_atomic-sparc.h: Ditto.
	* include/rw/_atomic-x86.h: Ditto.
	* include/rw/_atomic-xlc.h: Ditto.
	* include/rw/_atomic-x64.h: Ditto. Arrange 64-bit atomic
	functions into single #if/#endif block.
	* include/rw/_atomic-sync.h: Same.
	* include/rw/_atomic.h: Define generic bool, long and
	long long atomic functions only if the corresponding
	char/short/int/long atomic functions are defined.
	* include/rw/_mutex.h: Cleanup _RWSTD_NO_XXX_ATOMIC_OPS macros.
	(__rw_get_static_mutex): Check for presence of the int atomic
	operations instead of checking the PA RISC platform.


	2008-10-06  Farid Zaripov  <faridz@apache.org>
	* include/rw/_atomic.h: Check for __GNUG__ instead of __GNUC__ for consistency.
	Correct preprocessor condition for ICC on __i386__ and __x86_64 platforms.


	2008-10-08  Farid Zaripov  <faridz@apache.org>
	* include/rw/_atomic-sparc.h: Declare __rw_atomic_xxx64() functions
	only if atomic-sparc64.s file will be #included in atomic.s
	(use the same conditions as in the atomic.s file).
	* include/rw/_atomic.h: Use __sync_xxx() builtins on x86 platform
	on processors >= i486 only.


	2008-10-09  Farid Zaripov  <faridz@apache.org>
	* src/locale_body.h: Replace __CYGWIN32__ to __CYGWIN__ for consistency.
	* util/ctype.cpp: Ditto.
	* util/localedef.cpp: Ditto.


	2008-10-09  Farid Zaripov  <faridz@apache.org>
        * src/locale_body.h: Revert changes, accidentally committed in r703124. 
        * util/path.cpp: Replace __CYGWIN32__ to __CYGWIN__ for consistency.


git-svn-id: https://svn.apache.org/repos/asf/stdcxx/trunk@704153 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/include/rw/_atomic-deccxx.h b/include/rw/_atomic-deccxx.h
new file mode 100644
index 0000000..78b3279
--- /dev/null
+++ b/include/rw/_atomic-deccxx.h
@@ -0,0 +1,136 @@
+/***************************************************************************
+ *
+ * _atomic-deccxx.h - definitions of inline functions for atomic
+ *                    operations on ALPHA platform
+ *
+ * This is an internal header file used to implement the C++ Standard
+ * Library. It should never be #included directly by a program.
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software, Inc.
+ * 
+ **************************************************************************/
+
+// get declarations of __ATOMIC_XXX intrinsics
+#  include <machine/builtins.h>
+
+#define _RWSTD_NO_CHAR_ATOMIC_OPS
+#define _RWSTD_NO_SHORT_ATOMIC_OPS
+#define _RWSTD_NO_LLONG_ATOMIC_OPS
+
+_RWSTD_NAMESPACE (__rw) {
+
+// __ATOMIC_[DE|IN]CREMENT_[LONG|QUAD] and __ATOMIC_EXCH_[LONG|QUAD] are
+// intrinsic functions declared in <machine/builtins.h> that atomically
+// modify their argument and return its original value (__ATOMIC_XXX_LONG
+// is misnamed -- it actually operates on an int, not a long)
+
+inline int
+__rw_atomic_preincrement (int &__x, bool)
+{
+    return 1 + __ATOMIC_INCREMENT_LONG (&__x);
+}
+
+
+inline unsigned
+__rw_atomic_preincrement (unsigned &__x, bool)
+{
+    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (int&, __x),
+                                     false);
+}
+
+
+inline long
+__rw_atomic_preincrement (long &__x, bool)
+{
+    return 1 + __ATOMIC_INCREMENT_QUAD (&__x);
+}
+
+
+inline unsigned long
+__rw_atomic_preincrement (unsigned long &__x, bool)
+{
+    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (long&, __x),
+                                     false);
+}
+
+
+inline int
+__rw_atomic_predecrement (int &__x, bool)
+{
+    return __ATOMIC_DECREMENT_LONG (&__x) - 1;
+}
+
+
+inline unsigned
+__rw_atomic_predecrement (unsigned &__x, bool)
+{
+    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (int&, __x),
+                                     false);
+}
+
+
+inline long
+__rw_atomic_predecrement (long &__x, bool)
+{
+    return __ATOMIC_DECREMENT_QUAD (&__x) - 1;
+}
+
+
+inline unsigned long
+__rw_atomic_predecrement (unsigned long &__x, bool)
+{
+    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (long&, __x),
+                                     false);
+}
+
+
+inline int
+__rw_atomic_exchange (int &__x, int __y, bool)
+{
+    return __ATOMIC_EXCH_LONG (&__x, __y);
+}
+
+
+inline unsigned
+__rw_atomic_exchange (unsigned &__x, unsigned __y, bool)
+{
+    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (unsigned&, __x),
+                                 _RWSTD_STATIC_CAST (int, __y), false);
+}
+
+
+inline long
+__rw_atomic_exchange (long &__x, long __y, bool)
+{
+    return __ATOMIC_EXCH_QUAD (&__x, __y);
+}
+
+
+inline unsigned long
+__rw_atomic_exchange (unsigned long &__x, unsigned long __y, bool)
+{
+    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (long&, __x),
+                                 _RWSTD_STATIC_CAST (long, __y), false);
+}
+
+}   // namespace __rw
diff --git a/include/rw/_atomic-mipspro.h b/include/rw/_atomic-mipspro.h
new file mode 100644
index 0000000..4879409
--- /dev/null
+++ b/include/rw/_atomic-mipspro.h
@@ -0,0 +1,138 @@
+/***************************************************************************
+ *
+ * _atomic-mipspro.h - definitions of inline functions for atomic
+ *                     operations on MIPS platform
+ *
+ * This is an internal header file used to implement the C++ Standard
+ * Library. It should never be #included directly by a program.
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software, Inc.
+ * 
+ **************************************************************************/
+
+#  include <mutex.h>
+
+#define _RWSTD_NO_CHAR_ATOMIC_OPS
+#define _RWSTD_NO_SHORT_ATOMIC_OPS
+#define _RWSTD_NO_LLONG_ATOMIC_OPS
+
+_RWSTD_NAMESPACE (__rw) {
+
+inline unsigned
+__rw_atomic_preincrement (unsigned &__x, bool)
+{
+    return __add_then_test32 (&__x, 1U);
+}
+
+
+inline int
+__rw_atomic_preincrement (int &__x, bool)
+{
+    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (unsigned&, __x),
+                                     false);
+}
+
+
+inline unsigned
+__rw_atomic_predecrement (unsigned &__x, bool)
+{
+    return __add_then_test32 (&__x, unsigned (-1));
+}
+
+
+inline int
+__rw_atomic_predecrement (int &__x, bool)
+{
+    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (unsigned &, __x),
+                                     false);
+}
+
+
+inline unsigned
+__rw_atomic_exchange (unsigned &__x, unsigned __y, bool)
+{
+    return __test_and_set32 (&__x, __y);
+}
+
+
+inline int
+__rw_atomic_exchange (int &__x, int __y, bool)
+{
+    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (unsigned int&, __x),
+                                 _RWSTD_STATIC_CAST (unsigned int, __y), false);
+}
+
+
+#  if _RWSTD_INT_SIZE < _RWSTD_LONG_SIZE
+
+inline unsigned long
+__rw_atomic_preincrement (unsigned long &__x, bool)
+{
+    return __add_then_test (&__x, 1);
+}
+
+
+inline long
+__rw_atomic_preincrement (long &__x, bool)
+{
+    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST(unsigned long&,
+                                                             __x),
+                                     false);
+}
+
+inline unsigned long
+__rw_atomic_predecrement (unsigned long &__x, bool)
+{
+    return __add_then_test (&__x, -1);
+}
+
+
+inline long
+__rw_atomic_predecrement (long &__x, bool)
+{
+    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (unsigned long&,
+                                                              __x),
+                                     false);
+}
+
+
+inline unsigned long
+__rw_atomic_exchange (unsigned long &__x, unsigned long __y, bool)
+{
+    return __test_and_set (&__x, __y);
+}
+
+
+inline long
+__rw_atomic_exchange (long &__x, long __y, bool)
+{
+    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (unsigned long&, __x),
+                                 _RWSTD_STATIC_CAST (unsigned long, __y),
+                                 false);
+}
+
+#  else   // _RWSTD_INT_SIZE == _RWSTD_LONG_SIZE
+#    define _RWSTD_NO_LONG_ATOMIC_OPS
+#  endif   // _RWSTD_INT_SIZE < _RWSTD_LONG_SIZE
+
+}   // namespace __rw
diff --git a/include/rw/_atomic-mutex.h b/include/rw/_atomic-mutex.h
new file mode 100644
index 0000000..875df7f
--- /dev/null
+++ b/include/rw/_atomic-mutex.h
@@ -0,0 +1,119 @@
+/***************************************************************************
+ *
+ * _atomic-mutex.h - definitions of inline functions for atomic
+ *                   operations with using mutex object
+ *
+ * This is an internal header file used to implement the C++ Standard
+ * Library. It should never be #included directly by a program.
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software, Inc.
+ * 
+ **************************************************************************/
+
+#ifndef _RWSTD_RW_ATOMIC_MUTEX_H_INCLUDED
+#define _RWSTD_RW_ATOMIC_MUTEX_H_INCLUDED
+
+
+#ifndef _RWSTD_RW_MUTEX_H_INCLUDED
+#  include <rw/_mutex.h>
+#endif   // _RWSTD_RW_MUTEX_H_INCLUDED
+
+
+_RWSTD_NAMESPACE (__rw) {
+    
+// helper functions for atomic value [in|de]crement and exchange
+// the functions are atomic with respect to each other as long as
+// they are passed the same mutex by the callers
+template <class _TypeT>
+inline
+_TypeT __rw_atomic_preincrement (_TypeT &__t, __rw_mutex_base &__mutex)
+{
+    _RWSTD_MT_GUARD (__mutex);
+
+    return ++__t;
+}
+
+
+template <class _TypeT>
+inline
+_TypeT __rw_atomic_predecrement (_TypeT &__t, __rw_mutex_base &__mutex)
+{
+    _RWSTD_MT_GUARD (__mutex);
+
+    return --__t;
+}
+
+
+template <class _TypeT, class _TypeU>
+inline
+_TypeT __rw_atomic_exchange (_TypeT &__t, const _TypeU &__u,
+                             __rw_mutex_base &__mutex)
+{
+    _RWSTD_MT_GUARD (__mutex);
+
+    _TypeT __tmp = __t;
+
+#ifndef _WIN64
+    __t = __u;
+#else
+    // silence MSVC conversion warnings (cast breaks SunPro 5.3 and prior)
+    __t = _RWSTD_STATIC_CAST (_TypeT, __u);
+#endif
+
+    return __tmp;
+}
+
+
+// for use on class statics or on namespace-scope variables
+// the unused argument is only here so that all functions
+// can be called from the same set of macros
+
+template <class _TypeT>
+inline
+_TypeT __rw_atomic_preincrement (_TypeT &__t, bool)
+{
+    return __rw_atomic_preincrement (__t,
+                                     __rw_get_static_mutex ((_TypeT*)0));
+}
+
+
+template <class _TypeT>
+inline
+_TypeT __rw_atomic_predecrement (_TypeT &__t, bool)
+{
+    return __rw_atomic_predecrement (__t,
+                                     __rw_get_static_mutex ((_TypeT*)0));
+}
+
+
+template <class _TypeT, class _TypeU>
+inline
+_TypeT __rw_atomic_exchange (_TypeT &__t, const _TypeU &__u, bool)
+{
+    return __rw_atomic_exchange (__t, __u,
+                                 __rw_get_static_mutex ((_TypeT*)0));
+}
+
+}   // namespace __rw
+
+#endif   // _RWSTD_RW_ATOMIC_MUTEX_H_INCLUDED
diff --git a/include/rw/_atomic-parisc.h b/include/rw/_atomic-parisc.h
new file mode 100644
index 0000000..194c62b
--- /dev/null
+++ b/include/rw/_atomic-parisc.h
@@ -0,0 +1,100 @@
+/***************************************************************************
+ *
+ * _atomic-parisc.h - definitions of inline functions for atomic
+ *                    operations on PA RISC platform
+ *
+ * This is an internal header file used to implement the C++ Standard
+ * Library. It should never be #included directly by a program.
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software, Inc.
+ * 
+ **************************************************************************/
+
+#define _RWSTD_NO_CHAR_ATOMIC_OPS
+#define _RWSTD_NO_SHORT_ATOMIC_OPS
+#define _RWSTD_NO_INT_ATOMIC_OPS
+#define _RWSTD_NO_LONG_ATOMIC_OPS
+#define _RWSTD_NO_LLONG_ATOMIC_OPS
+
+_RWSTD_NAMESPACE (__rw) {
+    
+extern "C" {
+
+// special constraint: the value of both the argument and the result
+// must not be zero
+
+int __rw_atomic_incr32 (int*);
+int __rw_atomic_decr32 (int*);
+int __rw_atomic_xchg32 (int*, int);
+
+}   // extern "C"
+
+
+inline int
+__rw_string_atomic_preincrement (int &__x, bool)
+{
+    return  __rw_atomic_incr32 (&__x);
+}
+
+
+inline unsigned
+__rw_string_atomic_preincrement (unsigned &__x, bool)
+{
+  
+    return __rw_string_atomic_preincrement (_RWSTD_REINTERPRET_CAST(int&, __x),
+                                            false);
+}
+
+
+inline int
+__rw_string_atomic_predecrement (int &__x, bool)
+{
+    return  __rw_atomic_decr32 (&__x);
+}
+
+
+inline unsigned
+__rw_string_atomic_predecrement (unsigned &__x, bool)
+{
+  
+    return __rw_string_atomic_predecrement (_RWSTD_REINTERPRET_CAST(int&, __x),
+                                            false);
+}
+
+
+inline int
+__rw_string_atomic_exchange (int &__x, int __y, bool)
+{
+    return __rw_atomic_xchg32 (&__x, __y);
+}
+
+
+inline unsigned
+__rw_string_atomic_exchange (unsigned &__x, unsigned __y, bool)
+{
+    return __rw_string_atomic_exchange (_RWSTD_REINTERPRET_CAST(int&, __x),
+                                        _RWSTD_STATIC_CAST(int,__y),
+                                        false);
+} 
+
+}   // namespace __rw
diff --git a/include/rw/_atomic-sparc.h b/include/rw/_atomic-sparc.h
new file mode 100644
index 0000000..a9717cb
--- /dev/null
+++ b/include/rw/_atomic-sparc.h
@@ -0,0 +1,160 @@
+/***************************************************************************
+ *
+ * _atomic-sparc.h - definitions of inline functions for atomic
+ *                   operations on SPARC platform
+ *
+ * This is an internal header file used to implement the C++ Standard
+ * Library. It should never be #included directly by a program.
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software, Inc.
+ * 
+ **************************************************************************/
+
+_RWSTD_NAMESPACE (__rw) {
+
+#define _RWSTD_NO_CHAR_ATOMIC_OPS
+#define _RWSTD_NO_SHORT_ATOMIC_OPS
+#define _RWSTD_NO_LLONG_ATOMIC_OPS
+
+extern "C" {
+
+// define in assembler file "atomic-sparc.s" and "atomic-sparc64.s"
+// exchange returns the original value, and add returns the incremented
+// value
+
+int  __rw_atomic_xchg32 (int*, int);
+int  __rw_atomic_add32 (int*, int);
+
+#  if defined (__sparcv9) || defined (__sparcv9__)
+
+long __rw_atomic_xchg64 (long*, long);
+long __rw_atomic_add64 (long*, long);
+
+#  endif
+
+}   // extern "C"
+
+
+inline int
+__rw_atomic_preincrement (int &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
+    return __rw_atomic_add32 (&__x, 1);
+}
+
+
+inline unsigned
+__rw_atomic_preincrement (unsigned &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned));
+    return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (int*, &__x), 1);
+}
+
+
+inline int
+__rw_atomic_predecrement (int &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
+    return __rw_atomic_add32 (&__x, -1);
+}
+
+
+inline unsigned
+__rw_atomic_predecrement (unsigned &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned));
+    return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (int*, &__x), -1);
+}
+
+
+inline int
+__rw_atomic_exchange (int &__x, int __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
+    return __rw_atomic_xchg32 (&__x, __y);
+}
+
+
+inline unsigned
+__rw_atomic_exchange (unsigned &__x, unsigned __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned));
+    return __rw_atomic_xchg32 (_RWSTD_REINTERPRET_CAST (int*, &__x),
+                               _RWSTD_STATIC_CAST (int, __y));
+}
+
+#  if _RWSTD_INT_SIZE < _RWSTD_LONG_SIZE
+
+inline long
+__rw_atomic_preincrement (long &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
+    return __rw_atomic_add64 (&__x, 1);
+}
+
+
+inline unsigned long
+__rw_atomic_preincrement (unsigned long &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
+    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (long*, &__x), 1);
+}
+
+
+inline long
+__rw_atomic_predecrement (long &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
+    return __rw_atomic_add64 (&__x, -1);
+}
+
+
+inline unsigned long
+__rw_atomic_predecrement (unsigned long &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
+    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (long*, &__x), -1);
+}
+
+
+inline long
+__rw_atomic_exchange (long &__x, long __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
+    return __rw_atomic_xchg64 (&__x, __y);
+}
+
+
+inline unsigned long
+__rw_atomic_exchange (unsigned long &__x, unsigned long __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
+    return __rw_atomic_xchg64 (_RWSTD_REINTERPRET_CAST (long*, &__x),
+                               _RWSTD_STATIC_CAST (long, __y));
+}
+
+#  else   // _RWSTD_INT_SIZE == _RWSTD_LONG_SIZE
+#    define _RWSTD_NO_LONG_ATOMIC_OPS
+#  endif   // _RWSTD_INT_SIZE < _RWSTD_LONG_SIZE
+
+}   // namespace __rw
diff --git a/include/rw/_atomic-sync.h b/include/rw/_atomic-sync.h
new file mode 100644
index 0000000..d7541b2
--- /dev/null
+++ b/include/rw/_atomic-sync.h
@@ -0,0 +1,321 @@
+/***************************************************************************
+ *
+ * _atomic-sync.h - definitions of inline functions for atomic
+ *                  operations using __sync_xxx() functions set
+ *
+ * This is an internal header file used to implement the C++ Standard
+ * Library. It should never be #included directly by a program.
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software, Inc.
+ * 
+ **************************************************************************/
+
+#if defined (__ia64) && defined (__INTEL_COMPILER)
+#  include <ia64intrin.h>
+#endif
+
+_RWSTD_NAMESPACE (__rw) {
+
+inline char
+__rw_atomic_preincrement (char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
+    return __sync_add_and_fetch (&__x, 1);
+}
+
+
+inline signed char
+__rw_atomic_preincrement (signed char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
+    return __sync_add_and_fetch (&__x, 1);
+}
+
+
+inline unsigned char
+__rw_atomic_preincrement (unsigned char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
+    return __sync_add_and_fetch (&__x, 1);
+}
+
+
+inline short
+__rw_atomic_preincrement (short &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
+    return __sync_add_and_fetch (&__x, 1);
+}
+
+
+inline unsigned short
+__rw_atomic_preincrement (unsigned short &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
+    return __sync_add_and_fetch (&__x, 1);
+}
+
+
+inline int
+__rw_atomic_preincrement (int &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
+    return __sync_add_and_fetch (&__x, 1);
+}
+
+
+inline unsigned int
+__rw_atomic_preincrement (unsigned int &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
+    return __sync_add_and_fetch (&__x, 1);
+}
+
+
+inline char
+__rw_atomic_predecrement (char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
+    return __sync_sub_and_fetch (&__x, 1);
+}
+
+
+inline signed char
+__rw_atomic_predecrement (signed char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
+    return __sync_sub_and_fetch (&__x, 1);
+}
+
+
+inline unsigned char
+__rw_atomic_predecrement (unsigned char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
+    return __sync_sub_and_fetch (&__x, 1);
+}
+
+
+inline short
+__rw_atomic_predecrement (short &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
+    return __sync_sub_and_fetch (&__x, 1);
+}
+
+
+inline unsigned short
+__rw_atomic_predecrement (unsigned short &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
+    return __sync_sub_and_fetch (&__x, 1);
+}
+
+
+inline int
+__rw_atomic_predecrement (int &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
+    return __sync_sub_and_fetch (&__x, 1);
+}
+
+
+inline unsigned int
+__rw_atomic_predecrement (unsigned int &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
+    return __sync_sub_and_fetch (&__x, 1);
+}
+
+
+inline char
+__rw_atomic_exchange (char &__x, char __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
+    return __sync_lock_test_and_set (&__x, __y);
+}
+
+
+inline signed char
+__rw_atomic_exchange (signed char &__x, signed char __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
+    return __sync_lock_test_and_set (&__x, __y);
+}
+
+
+inline unsigned char
+__rw_atomic_exchange (unsigned char &__x, unsigned char __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
+    return __sync_lock_test_and_set (&__x, __y);
+}
+
+
+inline short
+__rw_atomic_exchange (short &__x, short __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
+    return __sync_lock_test_and_set (&__x, __y);
+}
+
+
+inline unsigned short
+__rw_atomic_exchange (unsigned short &__x, unsigned short __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
+    return __sync_lock_test_and_set (&__x, __y);
+}
+
+
+inline int
+__rw_atomic_exchange (int &__x, int __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
+    return __sync_lock_test_and_set (&__x, __y);
+}
+
+
+inline unsigned int
+__rw_atomic_exchange (unsigned int &__x, unsigned int __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
+    return __sync_lock_test_and_set (&__x, __y);
+}
+
+
+#if defined (__ia64) || defined (__x86_64)
+#  if 4 < _RWSTD_LONG_SIZE
+
+inline long
+__rw_atomic_preincrement (long &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
+    return __sync_add_and_fetch (&__x, 1);
+}
+
+
+inline unsigned long
+__rw_atomic_preincrement (unsigned long &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
+    return __sync_add_and_fetch (&__x, 1);
+}
+
+
+inline long
+__rw_atomic_predecrement (long &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
+    return __sync_sub_and_fetch (&__x, 1);
+}
+
+
+inline unsigned long
+__rw_atomic_predecrement (unsigned long &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
+    return __sync_sub_and_fetch (&__x, 1);
+}
+
+
+inline long
+__rw_atomic_exchange (long &__x, long __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
+    return __sync_lock_test_and_set (&__x, __y);
+}
+
+
+inline unsigned long
+__rw_atomic_exchange (unsigned long &__x, unsigned long __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
+    return __sync_lock_test_and_set (&__x, __y);
+}
+
+#  else
+#    define _RWSTD_NO_LONG_ATOMIC_OPS
+#  endif   // 4 < _RWSTD_LONG_SIZE
+
+
+#  if defined (_RWSTD_LONG_LONG) && (_RWSTD_LLONG_SIZE > _RWSTD_LONG_SIZE)
+
+inline _RWSTD_LONG_LONG
+__rw_atomic_preincrement (_RWSTD_LONG_LONG &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (_RWSTD_LONG_LONG));
+    return __sync_add_and_fetch (&__x, 1);
+}
+
+
+inline unsigned _RWSTD_LONG_LONG
+__rw_atomic_preincrement (unsigned _RWSTD_LONG_LONG &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned _RWSTD_LONG_LONG));
+    return __sync_add_and_fetch (&__x, 1);
+}
+
+
+inline _RWSTD_LONG_LONG
+__rw_atomic_predecrement (_RWSTD_LONG_LONG &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (_RWSTD_LONG_LONG));
+    return __sync_sub_and_fetch (&__x, 1);
+}
+
+
+inline unsigned _RWSTD_LONG_LONG
+__rw_atomic_predecrement (unsigned _RWSTD_LONG_LONG &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned _RWSTD_LONG_LONG));
+    return __sync_sub_and_fetch (&__x, 1);
+}
+
+
+inline _RWSTD_LONG_LONG
+__rw_atomic_exchange (_RWSTD_LONG_LONG &__x, _RWSTD_LONG_LONG __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (_RWSTD_LONG_LONG));
+    return __sync_lock_test_and_set (&__x, __y);
+}
+
+
+inline unsigned _RWSTD_LONG_LONG
+__rw_atomic_exchange (unsigned _RWSTD_LONG_LONG &__x,
+                      unsigned _RWSTD_LONG_LONG __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned _RWSTD_LONG_LONG));
+    return __sync_lock_test_and_set (&__x, __y);
+}
+
+#  else
+#    define _RWSTD_NO_LLONG_ATOMIC_OPS
+#  endif   // _RWSTD_LONG_LONG && _RWSTD_LLONG_SIZE > _RWSTD_LONG_SIZE
+
+#else   // !__ia64 && !__x86_64
+#  define _RWSTD_NO_LONG_ATOMIC_OPS
+#  define _RWSTD_NO_LLONG_ATOMIC_OPS
+#endif   // __ia64 || __x86_64
+
+}   // namespace __rw
diff --git a/include/rw/_atomic-x64.h b/include/rw/_atomic-x64.h
new file mode 100644
index 0000000..720d3d1
--- /dev/null
+++ b/include/rw/_atomic-x64.h
@@ -0,0 +1,510 @@
+/***************************************************************************
+ *
+ * _atomic-x64.h - definitions of inline functions for atomic
+ *                 operations on Intel IA64 and X64 platforms
+ *
+ * This is an internal header file used to implement the C++ Standard
+ * Library. It should never be #included directly by a program.
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software, Inc.
+ * 
+ **************************************************************************/
+
+#ifdef _MSC_VER
+extern "C" long __cdecl _InterlockedIncrement (volatile long*);
+extern "C" long __cdecl _InterlockedDecrement (volatile long*);
+extern "C" long __cdecl _InterlockedExchange (volatile long*, long);
+#  ifdef _RWSTD_MSVC
+#    pragma intrinsic (_InterlockedIncrement)
+#    pragma intrinsic (_InterlockedDecrement)
+#    pragma intrinsic (_InterlockedExchange)
+#  endif   // _RWSTD_MSVC
+
+#  if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
+extern "C" short __cdecl _InterlockedIncrement16 (volatile short*);
+extern "C" short __cdecl _InterlockedDecrement16 (volatile short*);
+#    pragma intrinsic (_InterlockedIncrement16)
+#    pragma intrinsic (_InterlockedDecrement16)
+#  endif   // _RWSTD_MSVC >= 1400
+
+#  ifdef _M_X64
+extern "C" long long __cdecl _InterlockedIncrement64 (volatile long long*);
+extern "C" long long __cdecl _InterlockedDecrement64 (volatile long long*);
+extern "C" long long __cdecl _InterlockedExchange64 (volatile long long*,
+                                                     long long);
+#    ifdef _RWSTD_MSVC
+#      pragma intrinsic (_InterlockedIncrement64)
+#      pragma intrinsic (_InterlockedDecrement64)
+#      pragma intrinsic (_InterlockedExchange64)
+#    endif   // _RWSTD_MSVC
+#  endif   // _M_X64
+#endif   // _MSC_VER
+
+
+_RWSTD_NAMESPACE (__rw) {
+
+extern "C" {
+
+_RWSTD_EXPORT _RWSTD_INT8_T
+__rw_atomic_xchg8  (_RWSTD_INT8_T*,  _RWSTD_INT8_T);
+
+_RWSTD_EXPORT _RWSTD_INT16_T
+__rw_atomic_xchg16 (_RWSTD_INT16_T*, _RWSTD_INT16_T);
+
+_RWSTD_EXPORT _RWSTD_INT32_T
+__rw_atomic_xchg32 (_RWSTD_INT32_T*, _RWSTD_INT32_T);
+
+
+_RWSTD_EXPORT _RWSTD_INT8_T
+__rw_atomic_add8  (_RWSTD_INT8_T*,  _RWSTD_INT8_T);
+
+_RWSTD_EXPORT _RWSTD_INT16_T
+__rw_atomic_add16 (_RWSTD_INT16_T*, _RWSTD_INT16_T);
+
+_RWSTD_EXPORT _RWSTD_INT32_T
+__rw_atomic_add32 (_RWSTD_INT32_T*, _RWSTD_INT32_T);
+
+#ifdef _RWSTD_INT64_T
+
+_RWSTD_EXPORT _RWSTD_INT64_T
+__rw_atomic_xchg64 (_RWSTD_INT64_T*, _RWSTD_INT64_T);
+
+_RWSTD_EXPORT _RWSTD_INT64_T
+__rw_atomic_add64 (_RWSTD_INT64_T*, _RWSTD_INT64_T);
+
+#endif   // _RWSTD_INT64_T
+
+}   // extern "C"
+
+
+inline char
+__rw_atomic_preincrement (char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
+
+    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
+                             +1);
+}
+
+
+inline signed char
+__rw_atomic_preincrement (signed char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
+
+    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
+                             +1);
+}
+
+
+inline unsigned char
+__rw_atomic_preincrement (unsigned char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
+
+    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
+                             +1);
+}
+
+
+inline short
+__rw_atomic_preincrement (short &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
+
+#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
+    return _InterlockedIncrement16 (&__x);
+#else
+    return __rw_atomic_add16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
+                              +1);
+#endif
+}
+
+
+inline unsigned short
+__rw_atomic_preincrement (unsigned short &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
+
+#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
+    return _InterlockedIncrement16 (_RWSTD_REINTERPRET_CAST (short*, &__x));
+#else
+    return __rw_atomic_add16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
+                              +1);
+#endif
+}
+
+
+inline int
+__rw_atomic_preincrement (int &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
+
+#ifdef _MSC_VER
+    return _InterlockedIncrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
+#else
+    return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
+                              +1);
+#endif
+}
+
+
+inline unsigned int
+__rw_atomic_preincrement (unsigned int &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
+
+#ifdef _MSC_VER
+    return _InterlockedIncrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
+#else
+    return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
+                              +1);
+#endif
+}
+
+
+inline char
+__rw_atomic_predecrement (char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
+
+    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
+                             -1);
+}
+
+
+inline signed char
+__rw_atomic_predecrement (signed char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
+
+    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
+                             -1);
+}
+
+
+inline unsigned char
+__rw_atomic_predecrement (unsigned char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
+
+    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
+                             -1);
+}
+
+
+inline short
+__rw_atomic_predecrement (short &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
+
+#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
+    return _InterlockedDecrement16 (&__x);
+#else
+    return __rw_atomic_add16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
+                              -1);
+#endif
+}
+
+
+inline unsigned short
+__rw_atomic_predecrement (unsigned short &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
+
+#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
+    return _InterlockedDecrement16 (_RWSTD_REINTERPRET_CAST (short*, &__x));
+#else
+    return __rw_atomic_add16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
+                              -1);
+#endif
+}
+
+
+inline int
+__rw_atomic_predecrement (int &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
+
+#ifdef _MSC_VER
+    return _InterlockedDecrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
+#else
+    return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
+                              -1);
+#endif
+}
+
+
+inline unsigned int
+__rw_atomic_predecrement (unsigned int &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
+
+#ifdef _MSC_VER
+    return _InterlockedDecrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
+#else
+    return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
+                              -1);
+#endif
+}
+
+
+inline char
+__rw_atomic_exchange (char &__x, char __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
+
+    return __rw_atomic_xchg8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
+                              _RWSTD_STATIC_CAST (_RWSTD_INT8_T, __y));
+}
+
+
+inline signed char
+__rw_atomic_exchange (signed char &__x, signed char __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
+
+    return __rw_atomic_xchg8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
+                              _RWSTD_STATIC_CAST (_RWSTD_INT8_T, __y));
+}
+
+
+inline unsigned char
+__rw_atomic_exchange (unsigned char &__x, unsigned char __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
+
+    return __rw_atomic_xchg8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
+                              _RWSTD_STATIC_CAST (_RWSTD_INT8_T, __y));
+}
+
+
+inline short
+__rw_atomic_exchange (short &__x, short __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
+
+    return __rw_atomic_xchg16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
+                               _RWSTD_STATIC_CAST (_RWSTD_INT16_T, __y));
+}
+
+
+inline unsigned short
+__rw_atomic_exchange (unsigned short &__x, unsigned short __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
+
+    return __rw_atomic_xchg16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
+                               _RWSTD_STATIC_CAST (_RWSTD_INT16_T, __y));
+}
+
+
+inline int
+__rw_atomic_exchange (int &__x, int __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
+
+#ifdef _MSC_VER
+    return _InterlockedExchange (_RWSTD_REINTERPRET_CAST (long*, &__x),
+                                 _RWSTD_STATIC_CAST (long, __y));
+#else
+    return __rw_atomic_xchg32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
+                               _RWSTD_STATIC_CAST (_RWSTD_INT32_T, __y));
+#endif
+}
+
+
+inline unsigned int
+__rw_atomic_exchange (unsigned int &__x, unsigned int __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
+
+#ifdef _MSC_VER
+    return _InterlockedExchange (_RWSTD_REINTERPRET_CAST (long*, &__x),
+                                 _RWSTD_STATIC_CAST (long, __y));
+#else
+    return __rw_atomic_xchg32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
+                               _RWSTD_STATIC_CAST (_RWSTD_INT32_T, __y));
+#endif
+}
+
+
+#if 4 < _RWSTD_LONG_SIZE
+
+inline long
+__rw_atomic_preincrement (long &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
+
+    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
+                              +1);
+}
+
+
+inline unsigned long
+__rw_atomic_preincrement (unsigned long &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
+
+    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
+                              +1);
+}
+
+
+inline long
+__rw_atomic_predecrement (long &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
+
+    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
+                              -1);
+}
+
+
+inline unsigned long
+__rw_atomic_predecrement (unsigned long &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
+
+    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
+                              -1);
+}
+
+
+inline long
+__rw_atomic_exchange (long &__x, long __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
+
+    return __rw_atomic_xchg64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
+                               _RWSTD_STATIC_CAST (_RWSTD_INT64_T, __y));
+}
+
+
+inline unsigned long
+__rw_atomic_exchange (unsigned long &__x, unsigned long __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
+
+    return __rw_atomic_xchg64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
+                               _RWSTD_STATIC_CAST (_RWSTD_INT64_T, __y));
+}
+
+#else
+#  define _RWSTD_NO_LONG_ATOMIC_OPS
+#endif   // 4 < _RWSTD_LONG_SIZE
+
+
+#if defined (_RWSTD_LONG_LONG) && (_RWSTD_LLONG_SIZE > _RWSTD_LONG_SIZE)
+
+inline _RWSTD_LONG_LONG
+__rw_atomic_preincrement (_RWSTD_LONG_LONG &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (_RWSTD_LONG_LONG));
+
+#ifdef _MSC_VER
+    return _InterlockedIncrement64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x));
+#else
+    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
+                              +1);
+#endif
+}
+
+
+inline unsigned _RWSTD_LONG_LONG
+__rw_atomic_preincrement (unsigned _RWSTD_LONG_LONG &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned _RWSTD_LONG_LONG));
+
+#ifdef _MSC_VER
+    return _InterlockedIncrement64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x));
+#else
+    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
+                              +1);
+#endif
+}
+
+
+inline _RWSTD_LONG_LONG
+__rw_atomic_predecrement (_RWSTD_LONG_LONG &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (_RWSTD_LONG_LONG));
+
+#ifdef _MSC_VER
+    return _InterlockedDecrement64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x));
+#else
+    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
+                              -1);
+#endif
+}
+
+
+inline unsigned _RWSTD_LONG_LONG
+__rw_atomic_predecrement (unsigned _RWSTD_LONG_LONG &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned _RWSTD_LONG_LONG));
+
+#ifdef _MSC_VER
+    return _InterlockedDecrement64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x));
+#else
+    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
+                              -1);
+#endif
+}
+
+
+inline _RWSTD_LONG_LONG
+__rw_atomic_exchange (_RWSTD_LONG_LONG &__x, _RWSTD_LONG_LONG __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (_RWSTD_LONG_LONG));
+
+#ifdef _MSC_VER
+    return _InterlockedExchange64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x),
+                                   _RWSTD_STATIC_CAST (__int64, __y));
+#else
+    return __rw_atomic_xchg64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
+                               _RWSTD_STATIC_CAST (_RWSTD_INT64_T, __y));
+#endif
+}
+
+
+inline unsigned _RWSTD_LONG_LONG
+__rw_atomic_exchange (unsigned _RWSTD_LONG_LONG &__x,
+                      unsigned _RWSTD_LONG_LONG __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned _RWSTD_LONG_LONG));
+
+#ifdef _MSC_VER
+    return _InterlockedExchange64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x),
+                                   _RWSTD_STATIC_CAST (__int64, __y));
+#else
+    return __rw_atomic_xchg64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
+                               _RWSTD_STATIC_CAST (_RWSTD_INT64_T, __y));
+#endif
+}
+
+#else
+#  define _RWSTD_NO_LLONG_ATOMIC_OPS
+#endif   // _RWSTD_LONG_LONG && _RWSTD_LLONG_SIZE > _RWSTD_LONG_SIZE
+
+}   // namespace __rw
diff --git a/include/rw/_atomic-x86.h b/include/rw/_atomic-x86.h
new file mode 100644
index 0000000..2ef2b5f
--- /dev/null
+++ b/include/rw/_atomic-x86.h
@@ -0,0 +1,328 @@
+/***************************************************************************
+ *
+ * _atomic-x86.h - definitions of inline functions for atomic
+ *                 operations on Intel X86 platform
+ *
+ * This is an internal header file used to implement the C++ Standard
+ * Library. It should never be #included directly by a program.
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software, Inc.
+ * 
+ **************************************************************************/
+
+#define _RWSTD_NO_LONG_ATOMIC_OPS
+#define _RWSTD_NO_LLONG_ATOMIC_OPS
+
+#ifdef _MSC_VER
+
+extern "C" long __cdecl _InterlockedIncrement (volatile long*);
+extern "C" long __cdecl _InterlockedDecrement (volatile long*);
+extern "C" long __cdecl _InterlockedExchange (volatile long*, long);
+#  ifdef _RWSTD_MSVC
+#    pragma intrinsic (_InterlockedIncrement)
+#    pragma intrinsic (_InterlockedDecrement)
+#    pragma intrinsic (_InterlockedExchange)
+#  endif   // _RWSTD_MSVC
+
+#  if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
+extern "C" short __cdecl _InterlockedIncrement16 (volatile short*);
+extern "C" short __cdecl _InterlockedDecrement16 (volatile short*);
+#    pragma intrinsic (_InterlockedIncrement16)
+#    pragma intrinsic (_InterlockedDecrement16)
+#  endif   // _RWSTD_MSVC >= 1400
+
+#elif defined (_RWSTD_INTERLOCKED_T)
+
+extern "C" {
+
+__declspec (dllimport) long __stdcall
+InterlockedIncrement (_RWSTD_INTERLOCKED_T*);
+
+__declspec (dllimport) long __stdcall
+InterlockedDecrement (_RWSTD_INTERLOCKED_T*);
+
+__declspec (dllimport) long __stdcall
+InterlockedExchange (_RWSTD_INTERLOCKED_T*, long);
+
+}   // extern "C"
+
+inline long _InterlockedIncrement (volatile long *__x)
+{
+    return InterlockedIncrement (
+        _RWSTD_CONST_CAST (_RWSTD_INTERLOCKED_T*, __x));
+}
+
+inline long _InterlockedDecrement (volatile long *__x)
+{
+    return InterlockedDecrement (
+        _RWSTD_CONST_CAST (_RWSTD_INTERLOCKED_T*, __x));
+}
+
+inline long _InterlockedExchange (volatile long *__x, long __y)
+{
+    return InterlockedExchange (
+        _RWSTD_CONST_CAST (_RWSTD_INTERLOCKED_T*, __x), __y);
+}
+
+#endif   // _MSC_VER
+
+
+_RWSTD_NAMESPACE (__rw) {
+
+extern "C" {
+
+_RWSTD_EXPORT char __rw_atomic_add8 (char*, int);
+_RWSTD_EXPORT short __rw_atomic_add16 (short*, short);
+_RWSTD_EXPORT int __rw_atomic_add32 (int*, int);
+
+_RWSTD_EXPORT char __rw_atomic_xchg8 (char*, char);
+_RWSTD_EXPORT short __rw_atomic_xchg16 (short*, short);
+_RWSTD_EXPORT int __rw_atomic_xchg32 (int*, int);
+
+}   // extern "C"
+
+
+inline char
+__rw_atomic_preincrement (char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
+    return __rw_atomic_add8 (&__x, +1);
+}
+
+
+inline signed char
+__rw_atomic_preincrement (signed char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
+    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (char*, &__x), +1);
+}
+
+
+inline unsigned char
+__rw_atomic_preincrement (unsigned char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
+    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (char*, &__x), +1);
+}
+
+
+inline short
+__rw_atomic_preincrement (short &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
+
+#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
+    return _InterlockedIncrement16 (&__x);
+#else
+    return __rw_atomic_add16 (&__x, +1);
+#endif
+}
+
+
+inline unsigned short
+__rw_atomic_preincrement (unsigned short &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
+
+#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
+    return _InterlockedIncrement16 (_RWSTD_REINTERPRET_CAST (short*, &__x));
+#else
+    return __rw_atomic_add16 (_RWSTD_REINTERPRET_CAST (short*, &__x), +1);
+#endif
+}
+
+
+inline int
+__rw_atomic_preincrement (int &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
+
+#ifdef _MSC_VER
+    return _InterlockedIncrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
+#else
+    return __rw_atomic_add32 (&__x, 1);
+#endif
+}
+
+
+inline unsigned int
+__rw_atomic_preincrement (unsigned int &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
+
+#ifdef _MSC_VER
+    return _InterlockedIncrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
+#else
+    return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (int*, &__x), 1);
+#endif
+}
+
+
+inline char
+__rw_atomic_predecrement (char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
+    return __rw_atomic_add8 (&__x, -1);
+}
+
+
+inline signed char
+__rw_atomic_predecrement (signed char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
+    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (char*, &__x), -1);
+}
+
+
+inline unsigned char
+__rw_atomic_predecrement (unsigned char &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
+    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (char*, &__x), -1);
+}
+
+
+inline short
+__rw_atomic_predecrement (short &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
+
+#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
+    return _InterlockedDecrement16 (&__x);
+#else
+    return __rw_atomic_add16 (&__x, -1);
+#endif
+}
+
+
+inline unsigned short
+__rw_atomic_predecrement (unsigned short &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
+
+#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
+    return _InterlockedDecrement16 (_RWSTD_REINTERPRET_CAST (short*, &__x));
+#else
+    return __rw_atomic_add16 (_RWSTD_REINTERPRET_CAST (short*, &__x), -1);
+#endif
+}
+
+
+inline int
+__rw_atomic_predecrement (int &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
+
+#ifdef _MSC_VER
+    return _InterlockedDecrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
+#else
+    return __rw_atomic_add32 (&__x, -1);
+#endif
+}
+
+
+inline unsigned int
+__rw_atomic_predecrement (unsigned int &__x, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
+
+#ifdef _MSC_VER
+    return _InterlockedDecrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
+#else
+    return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (int*, &__x), -1);
+#endif
+}
+
+
+inline char
+__rw_atomic_exchange (char &__x, char __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
+    return __rw_atomic_xchg8 (&__x, __y);
+}
+
+
+inline signed char
+__rw_atomic_exchange (signed char &__x, signed char __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
+    return __rw_atomic_xchg8 (_RWSTD_REINTERPRET_CAST (char*, &__x),
+                              _RWSTD_STATIC_CAST (char, __y));
+}
+
+
+inline unsigned char
+__rw_atomic_exchange (unsigned char &__x, unsigned char __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
+    return __rw_atomic_xchg8 (_RWSTD_REINTERPRET_CAST (char*, &__x),
+                              _RWSTD_STATIC_CAST (char, __y));
+}
+
+
+inline short
+__rw_atomic_exchange (short &__x, short __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
+    return __rw_atomic_xchg16 (&__x, __y);
+}
+
+
+inline unsigned short
+__rw_atomic_exchange (unsigned short &__x, unsigned short __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
+    return __rw_atomic_xchg16 (_RWSTD_REINTERPRET_CAST (short*, &__x),
+                               _RWSTD_STATIC_CAST (short, __y));
+}
+
+
+inline int
+__rw_atomic_exchange (int &__x, int __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
+
+#ifdef _MSC_VER
+    return _InterlockedExchange (_RWSTD_REINTERPRET_CAST (long*, &__x),
+                                 _RWSTD_STATIC_CAST (long, __y));
+#else
+    return __rw_atomic_xchg32 (&__x, __y);
+#endif
+}
+
+
+inline unsigned int
+__rw_atomic_exchange (unsigned int &__x, unsigned int __y, bool)
+{
+    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
+
+#ifdef _MSC_VER
+    return _InterlockedExchange (_RWSTD_REINTERPRET_CAST (long*, &__x),
+                                 _RWSTD_STATIC_CAST (long, __y));
+#else
+    return __rw_atomic_xchg32 (_RWSTD_REINTERPRET_CAST (int*, &__x),
+                               _RWSTD_STATIC_CAST (int, __y));
+#endif
+}
+
+}   // namespace __rw
diff --git a/include/rw/_atomic-xlc.h b/include/rw/_atomic-xlc.h
new file mode 100644
index 0000000..1f7d41c
--- /dev/null
+++ b/include/rw/_atomic-xlc.h
@@ -0,0 +1,148 @@
+/***************************************************************************
+ *
+ * _atomic-xlc.h - definitions of inline functions for atomic
+ *                 operations on POWERPC platform
+ *
+ * This is an internal header file used to implement the C++ Standard
+ * Library. It should never be #included directly by a program.
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software, Inc.
+ * 
+ **************************************************************************/
+
+#include <sys/atomic_op.h>
+
+#define _RWSTD_NO_CHAR_ATOMIC_OPS
+#define _RWSTD_NO_SHORT_ATOMIC_OPS
+#define _RWSTD_NO_LLONG_ATOMIC_OPS
+
+_RWSTD_NAMESPACE (__rw) {
+
+inline int
+__rw_atomic_preincrement (int &__x, bool)
+{
+    return fetch_and_add (&__x, 1) + 1;
+}
+
+
+inline unsigned
+__rw_atomic_preincrement (unsigned &__x, bool)
+{
+    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (int&, __x),
+                                     false);
+}
+
+
+inline int
+__rw_atomic_predecrement (int &__x, bool)
+{
+    return fetch_and_add(&__x,-1) - 1;
+}
+
+
+inline unsigned
+__rw_atomic_predecrement (unsigned &__x, bool)
+{
+    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (int&, __x),
+                                     false);
+}
+
+
+inline int
+__rw_atomic_exchange (int &__x, int __y, bool)
+{
+    int __tmp;
+
+    do {
+        __tmp = __x;
+    } while (!compare_and_swap (&__x, &__tmp, __y));
+
+    return __tmp;
+}
+
+
+inline unsigned
+__rw_atomic_exchange (unsigned &__x, unsigned __y, bool)
+{
+    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (int&, __x),
+                                 _RWSTD_STATIC_CAST (int, __y), false);
+}
+
+
+#  if _RWSTD_INT_SIZE < _RWSTD_LONG_SIZE
+
+inline long
+__rw_atomic_preincrement (long &__x, bool)
+{
+    return fetch_and_addlp (&__x, 1) + 1;
+}
+
+
+inline unsigned long
+__rw_atomic_preincrement (unsigned long &__x, bool)
+{
+  return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (long&, __x),
+                                   false);
+}
+
+
+inline long
+__rw_atomic_predecrement (long &__x, bool)
+{
+    return fetch_and_addlp (&__x, -1) - 1;
+}
+
+
+inline unsigned long
+__rw_atomic_predecrement (unsigned long &__x, bool)
+{
+    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (long&, __x),
+                                     false);
+}
+
+
+inline long
+__rw_atomic_exchange (long &__x, long __y, bool)
+{
+    long __tmp;
+
+    do {
+        __tmp = __x;
+    } while (!compare_and_swaplp (&__x, &__tmp, __y));
+
+    return __tmp;
+}
+
+
+inline unsigned long
+__rw_atomic_exchange (unsigned long &__x, unsigned long __y, bool)
+{
+    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (long&, __x),
+                                 _RWSTD_STATIC_CAST (long, __y), false);
+}
+
+#  else   // _RWSTD_INT_SIZE == _RWSTD_LONG_SIZE
+#    define _RWSTD_NO_LONG_ATOMIC_OPS
+#  endif   // _RWSTD_INT_SIZE < _RWSTD_LONG_SIZE
+
+}   // namespace __rw
diff --git a/include/rw/_atomic.h b/include/rw/_atomic.h
new file mode 100644
index 0000000..64548b7
--- /dev/null
+++ b/include/rw/_atomic.h
@@ -0,0 +1,280 @@
+/***************************************************************************
+ *
+ * _atomic.h - definitions of inline functions for atomic operations
+ *
+ * This is an internal header file used to implement the C++ Standard
+ * Library. It should never be #included directly by a program.
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software, Inc.
+ * 
+ **************************************************************************/
+
+#ifndef _RWSTD_RW_ATOMIC_H_INCLUDED
+#define _RWSTD_RW_ATOMIC_H_INCLUDED
+
+
+#if __GNUG__ >= 3
+#  pragma GCC system_header
+#endif   // gcc >= 3
+
+
+#ifndef _RWSTD_RW_DEFS_H_INCLUDED
+#  include <rw/_defs.h>
+#endif   // _RWSTD_RW_DEFS_H_INCLUDED
+
+
+#ifdef _RWSTD_REENTRANT
+
+#  if defined (_RWSTD_NO_ATOMIC_OPS)
+     // do nothing
+#  elif defined (__DECCXX)
+#    include <rw/_atomic-deccxx.h>
+#  elif defined (__sparc) && (defined (__SUNPRO_CC) || defined (__GNUG__))
+#    include <rw/_atomic-sparc.h>
+#  elif defined (_AIX43) && defined (__IBMCPP__)
+#    include <rw/_atomic-xlc.h>
+#  elif defined (__sgi) && defined (__host_mips)
+#    include <rw/_atomic-mipspro.h>
+#  elif defined (_PA_RISC2_0)
+#    include <rw/_atomic-parisc.h>
+#  elif defined (__GNUG__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 401) \
+     && (defined (__i486__) || defined (__x86_64) || defined (__ia64)) \
+     && !defined (__INTEL_COMPILER)                                    \
+     || (defined (__INTEL_COMPILER) && defined (__ia64))
+#    include <rw/_atomic-sync.h>
+#  elif defined (__i386__) && (defined (__GNUG__) \
+     || defined (__INTEL_COMPILER)) || defined (_M_IX86)
+#    include <rw/_atomic-x86.h>
+#  elif defined (__ia64) || defined (__x86_64) || defined (_M_X64)
+#    include <rw/_atomic-x64.h>
+#  else
+#    define _RWSTD_NO_ATOMIC_OPS
+#  endif
+
+#  ifndef _RWSTD_NO_ATOMIC_OPS
+
+/********************** generic bool functions ************************/
+
+#    ifndef _RWSTD_NO_BOOL
+
+#      if   _RWSTD_BOOL_SIZE == _RWSTD_CHAR_SIZE  \
+         && !defined (_RWSTD_NO_CHAR_ATOMIC_OPS)
+#        define _RWSTD_BOOL_TYPE char
+#      elif _RWSTD_BOOL_SIZE == _RWSTD_SHORT_SIZE \
+         && !defined (_RWSTD_NO_SHORT_ATOMIC_OPS)
+#        define _RWSTD_BOOL_TYPE short
+#      elif _RWSTD_BOOL_SIZE == _RWSTD_INT_SIZE   \
+         && !defined (_RWSTD_NO_INT_ATOMIC_OPS)
+#        define _RWSTD_BOOL_TYPE int
+#      endif
+
+#      ifdef _RWSTD_BOOL_TYPE
+
+_RWSTD_NAMESPACE (__rw) {
+
+inline bool
+__rw_atomic_exchange (bool &__x, bool __y, bool)
+{
+    return 0 != __rw_atomic_exchange (
+                    _RWSTD_REINTERPRET_CAST (_RWSTD_BOOL_TYPE&, __x),
+                    _RWSTD_STATIC_CAST (_RWSTD_BOOL_TYPE, __y),
+                    false);
+}
+
+}   // namespace __rw
+
+#        undef _RWSTD_BOOL_TYPE
+#      endif   // _RWSTD_BOOL_TYPE
+
+#    endif   // _RWSTD_NO_BOOL
+
+
+/********************** generic long functions ************************/
+
+#    if   _RWSTD_LONG_SIZE == _RWSTD_INT_SIZE \
+       && defined (_RWSTD_NO_LONG_ATOMIC_OPS) \
+       && !defined (_RWSTD_NO_INT_ATOMIC_OPS)
+
+#      undef _RWSTD_NO_LONG_ATOMIC_OPS
+
+#      if 6 == _RWSTD_HP_aCC_MAJOR
+         // suppress HP aCC 64 bit migration remark: conversion from
+         // "long *" to "int *" may cause target of pointers to have
+         // a different size
+#        pragma diag_suppress 4230
+#      endif   // HP aCC 6
+
+_RWSTD_NAMESPACE (__rw) {
+
+inline long
+__rw_atomic_preincrement (long &__x, bool)
+{
+    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (int&, __x),
+                                     false);
+}
+
+inline unsigned long
+__rw_atomic_preincrement (unsigned long &__x, bool)
+{
+    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (int&, __x),
+                                     false);
+}
+
+inline long
+__rw_atomic_predecrement (long &__x, bool)
+{
+    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (int&, __x),
+                                     false);
+}
+
+inline unsigned long
+__rw_atomic_predecrement (unsigned long &__x, bool)
+{
+    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (int&, __x),
+                                     false);
+}
+
+inline long
+__rw_atomic_exchange (long &__x, long __y, bool)
+{
+    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (int&, __x),
+                                 _RWSTD_STATIC_CAST (int, __y),
+                                 false);
+}
+
+inline unsigned long
+__rw_atomic_exchange (unsigned long &__x,
+                      unsigned long __y, bool)
+{
+    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (int&, __x),
+                                 _RWSTD_STATIC_CAST (int, __y),
+                                 false);
+}
+
+}   // namespace __rw
+
+#      if 6 == _RWSTD_HP_aCC_MAJOR
+#        pragma diag_default 4230
+#      endif   // HP aCC 6
+
+#    endif   // _RWSTD_LONG_SIZE == _RWSTD_INT_SIZE
+
+
+/********************** generic long long functions *******************/
+
+#    if   defined (_RWSTD_LONG_LONG)            \
+       && _RWSTD_LLONG_SIZE == _RWSTD_LONG_SIZE \
+       && defined (_RWSTD_NO_LLONG_ATOMIC_OPS)  \
+       && !defined (_RWSTD_NO_LONG_ATOMIC_OPS)
+
+#      undef _RWSTD_NO_LLONG_ATOMIC_OPS
+
+_RWSTD_NAMESPACE (__rw) {
+    
+inline _RWSTD_LONG_LONG
+__rw_atomic_preincrement (_RWSTD_LONG_LONG &__x, bool)
+{
+    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (long&, __x),
+                                     false);
+}
+
+inline unsigned _RWSTD_LONG_LONG
+__rw_atomic_preincrement (unsigned _RWSTD_LONG_LONG &__x, bool)
+{
+    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (long&, __x),
+                                     false);
+}
+
+inline _RWSTD_LONG_LONG
+__rw_atomic_predecrement (_RWSTD_LONG_LONG &__x, bool)
+{
+    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (long&, __x),
+                                     false);
+}
+
+inline unsigned _RWSTD_LONG_LONG
+__rw_atomic_predecrement (unsigned _RWSTD_LONG_LONG &__x, bool)
+{
+    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (long&, __x),
+                                     false);
+}
+
+inline _RWSTD_LONG_LONG
+__rw_atomic_exchange (_RWSTD_LONG_LONG &__x, _RWSTD_LONG_LONG __y, bool)
+{
+    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (long&, __x),
+                                 _RWSTD_STATIC_CAST (long, __y),
+                                 false);
+}
+
+inline unsigned _RWSTD_LONG_LONG
+__rw_atomic_exchange (unsigned _RWSTD_LONG_LONG &__x,
+                      unsigned _RWSTD_LONG_LONG __y, bool)
+{
+    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (long&, __x),
+                                 _RWSTD_STATIC_CAST (long, __y),
+                                 false);
+}
+
+}   // namespace __rw
+
+#    endif   // _RWSTD_LONG_LONG && _RWSTD_LLONG_SIZE == _RWSTD_LONG_SIZE
+
+#  endif   // _RWSTD_NO_ATOMIC_OPS
+
+#else   // if !defined (_RWSTD_REENTRANT)
+
+_RWSTD_NAMESPACE (__rw) {
+    
+// atomic in a single-threaded environment
+template <class _TypeT, class _TypeU>
+inline
+_TypeT __rw_atomic_exchange (_TypeT &__t, const _TypeU &__u, bool)
+{
+    _TypeT __tmp = __t;
+    __t = _TypeT (__u);
+    return __tmp;
+}
+
+}   // namespace __rw
+
+#endif   // _RWSTD_REENTRANT
+
+
+_RWSTD_NAMESPACE (__rw) {
+
+// available in all environments (ST and MT), used along with
+// __rw_atomic_exchange<>() from conditional expressions in iostreams
+template <class _TypeT, class _TypeU>
+inline
+_TypeT __rw_ordinary_exchange (_TypeT &__t, const _TypeU &__u)
+{
+    _TypeT __tmp = __t;
+    __t = __u;
+    return __tmp;
+}
+
+}   // namespace __rw
+
+
+#endif   // _RWSTD_RW_ATOMIC_H_INCLUDED
diff --git a/include/rw/_mutex-dce.h b/include/rw/_mutex-dce.h
new file mode 100644
index 0000000..7beaef8
--- /dev/null
+++ b/include/rw/_mutex-dce.h
@@ -0,0 +1,43 @@
+/***************************************************************************
+ *
+ * _mutex-dce.h - definitions of classes for thread safety using DCE threads
+ *
+ * This is an internal header file used to implement the C++ Standard
+ * Library. It should never be #included directly by a program.
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software, Inc.
+ * 
+ **************************************************************************/
+
+#if defined (_RWSTD_NO_DCE_PTHREAD_H)
+#  include <pthread.h>
+#else
+#  include <dce/pthread.h>
+#endif
+
+#define _RWSTD_MUTEX_INIT(mutex) \
+        pthread_mutex_init (&mutex, pthread_mutexattr_default)
+#define _RWSTD_MUTEX_DESTROY(mutex)   pthread_mutex_destroy (&mutex)
+#define _RWSTD_MUTEX_LOCK(mutex)      pthread_mutex_lock (&mutex)
+#define _RWSTD_MUTEX_UNLOCK(mutex)    pthread_mutex_unlock (&mutex)
+#define _RWSTD_MUTEX_T                pthread_mutex_t
diff --git a/include/rw/_mutex-os2.h b/include/rw/_mutex-os2.h
new file mode 100644
index 0000000..a0fb0fc
--- /dev/null
+++ b/include/rw/_mutex-os2.h
@@ -0,0 +1,42 @@
+/***************************************************************************
+ *
+ * _mutex-os2.h - definitions of classes for thread safety using OS2 threads
+ *
+ * This is an internal header file used to implement the C++ Standard
+ * Library. It should never be #included directly by a program.
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software, Inc.
+ * 
+ **************************************************************************/
+
+#define INCL_DOSSEMAPHORES
+
+#include <os2.h>
+
+#define _RWSTD_MUTEX_INIT(mutex) \
+        DosCreateMutexSem (0, &mutex, DC_SEM_SHARED,FALSE)
+#define _RWSTD_MUTEX_DESTROY(mutex)   DosCloseMutexSem (mutex)
+#define _RWSTD_MUTEX_LOCK(mutex) \
+        DosRequestMutexSem (mutex, SEM_INDEFINITE_WAIT)
+#define _RWSTD_MUTEX_UNLOCK(mutex)    DosReleaseMutexSem (mutex)
+#define _RWSTD_MUTEX_T                HMTX
diff --git a/include/rw/_mutex-pthread.h b/include/rw/_mutex-pthread.h
new file mode 100644
index 0000000..4987155
--- /dev/null
+++ b/include/rw/_mutex-pthread.h
@@ -0,0 +1,75 @@
+/***************************************************************************
+ *
+ * _mutex-pthread.h - definitions of classes for thread safety
+ *                    using POSIX threads
+ *
+ * This is an internal header file used to implement the C++ Standard
+ * Library. It should never be #included directly by a program.
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software, Inc.
+ * 
+ **************************************************************************/
+
+#if    defined (_RWSTD_EDG_ECCP) && defined (_RWSTD_OS_LINUX) \
+    && defined (_RWSTD_NO_LONG_LONG)
+   // disable error #450-D: the type "long long" is nonstandard
+   // when using the vanilla EDG eccp in strict mode (i.e., w/o
+   // long long support)
+#  pragma diag_suppress 450
+#endif   // EDG eccp on Linux
+
+// LinuxThreads man page:
+//   "Variables of type pthread_mutex_t can also be initialized
+//    statically, using the constants  PTHREAD_MUTEX_INITIALIZER
+//    (for fast mutexes), PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+//    (for recursive mutexes), and PTHREAD_ERRORCHECK_MUTEX_INI-
+//    TIALIZER_NP (for error checking mutexes)."
+//    ...
+//    "Attempting to initialize an already initialized mutex results
+//    in undefined behavior."
+
+#include <pthread.h>
+
+#define _RWSTD_MUTEX_INIT(mutex)      pthread_mutex_init (&mutex, 0)
+#define _RWSTD_MUTEX_DESTROY(mutex)   pthread_mutex_destroy (&mutex)
+#define _RWSTD_MUTEX_LOCK(mutex)      pthread_mutex_lock (&mutex)
+#define _RWSTD_MUTEX_UNLOCK(mutex)    pthread_mutex_unlock (&mutex)
+#define _RWSTD_MUTEX_T                pthread_mutex_t
+
+#if defined (__GNUG__) && defined (__osf__)
+   // prevent g++ warnings about missing initializers
+   // see <pthread.h> for explanation of _PTHREAD_NOMETER_STATIC
+#  ifndef _PTHREAD_NOMETER_STATIC
+#    define _RWSTD_MUTEX_INITIALIZER \
+            { _PTHREAD_MSTATE_SLOW, _PTHREAD_MVALID | _PTHREAD_MVF_STA, \
+              0, 0, 0, 0, 0, 0 }
+#  else   // if defined (_PTHREAD_NOMETER_STATIC)
+#    define _RWSTD_MUTEX_INITIALIZER
+            { 0, _PTHREAD_MVALID | _PTHREAD_MVF_STA, 0, 0, 0, 0, 0, 0 }
+#  endif   // _PTHREAD_NOMETER_STATIC
+#elif defined (__GNUG__) && defined (__sgi__)
+   // prevent g++ warnings about a partly bracketed initializer
+#  define _RWSTD_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
+#else
+#  define _RWSTD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+#endif
diff --git a/include/rw/_mutex-solaris.h b/include/rw/_mutex-solaris.h
new file mode 100644
index 0000000..8602c8a
--- /dev/null
+++ b/include/rw/_mutex-solaris.h
@@ -0,0 +1,46 @@
+/***************************************************************************
+ *
+ * _mutex-solaris.h - definitions of classes for thread safety
+ *                    using Solaris threads
+ *
+ * This is an internal header file used to implement the C++ Standard
+ * Library. It should never be #included directly by a program.
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software, Inc.
+ * 
+ **************************************************************************/
+
+// SunOS 5.7 Threads Library:
+//   "A statically  allocated  mutex does  not  need to be explicitly
+//   initialized; by default, a statically allocated mutex is initialized
+//   with  all  zeros and its scope is set to be within the calling
+//   process."
+
+#include <synch.h>
+#include <thread.h>
+
+#define _RWSTD_MUTEX_INIT(mutex)      mutex_init (&mutex, USYNC_THREAD, 0)
+#define _RWSTD_MUTEX_DESTROY(mutex)   mutex_destroy (&mutex)
+#define _RWSTD_MUTEX_LOCK(mutex)      mutex_lock (&mutex)
+#define _RWSTD_MUTEX_UNLOCK(mutex)    mutex_unlock (&mutex)
+#define _RWSTD_MUTEX_T                mutex_t
diff --git a/include/rw/_mutex-win32.h b/include/rw/_mutex-win32.h
new file mode 100644
index 0000000..f3998e2
--- /dev/null
+++ b/include/rw/_mutex-win32.h
@@ -0,0 +1,159 @@
+/***************************************************************************
+ *
+ * _mutex-win32.h - definitions of classes for thread safety
+ *                  using Windows threads
+ *
+ * This is an internal header file used to implement the C++ Standard
+ * Library. It should never be #included directly by a program.
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1994-2008 Rogue Wave Software, Inc.
+ * 
+ **************************************************************************/
+
+#ifdef __MINGW32__
+#  define _RWSTD_CRITICAL_SECTION _CRITICAL_SECTION
+#else
+#  define _RWSTD_CRITICAL_SECTION _RTL_CRITICAL_SECTION
+#endif
+
+#ifdef _RWSTD_NO_FWD_DECLARATIONS
+
+   // #including <windows.h> without WIN32_LEAN_AND_MEAN macro defined
+   // may cause an errors "WinSock.h has already been included"
+   // when <winsock2.h> has been included after this header
+#  include <windows.h>
+#  define _RWSTD_MUTEX_T _RWSTD_CRITICAL_SECTION
+
+#else   // if !defined (_RWSTD_NO_FWD_DECLARATIONS)
+
+ // avoid #including this header (MFC doesn't like it)
+ // #  include <windows.h>
+
+extern "C" {
+
+// but rather declare these globals here
+struct _RWSTD_CRITICAL_SECTION;
+
+__declspec (dllimport) void __stdcall
+InitializeCriticalSection (_RWSTD_CRITICAL_SECTION*);
+
+__declspec (dllimport) void __stdcall
+EnterCriticalSection (_RWSTD_CRITICAL_SECTION*);
+
+__declspec (dllimport) void __stdcall
+LeaveCriticalSection (_RWSTD_CRITICAL_SECTION*);
+
+__declspec (dllimport) void __stdcall
+DeleteCriticalSection (_RWSTD_CRITICAL_SECTION*);
+
+}   // extern "C"
+
+_RWSTD_NAMESPACE (__rw) { 
+
+// fake critical section type
+union __rw_critical_section {
+    long _C_pad;   // force alignment
+
+#  ifndef _WIN64
+    char _C_buf [24 /* == sizeof (_RTL_CRITICAL_SECTION) */];
+#  else    // #ifdef _WIN64
+    char _C_buf [40 /* == sizeof (_RTL_CRITICAL_SECTION) */];
+#  endif   // _WIN64
+};
+
+#  define _RWSTD_MUTEX_T _RW::__rw_critical_section
+
+}   // namespace __rw
+
+#endif   // _RWSTD_NO_FWD_DECLARATIONS
+
+
+_RWSTD_NAMESPACE (__rw) { 
+
+#ifndef _MSC_VER
+#  define __try               if (1)
+#  define __except(ignore)    else if (0)
+#endif   // _MSC_VER
+
+// Win32/64 throws non-C++ exceptions rather than returning error status
+// from some system calls like most other operating systems do
+
+inline int __rw_mutex_init (_RWSTD_CRITICAL_SECTION *__mutex)
+{
+    __try {
+        InitializeCriticalSection (__mutex);
+    }
+    __except (1) {
+        return -1;
+    }
+    return 0;
+}
+
+inline int __rw_mutex_destroy (_RWSTD_CRITICAL_SECTION *__mutex)
+{
+    __try {
+        DeleteCriticalSection (__mutex);
+    }
+    __except (1) {
+        return -1;
+    }
+    return 0;
+}
+
+inline int __rw_mutex_lock (_RWSTD_CRITICAL_SECTION *__mutex)
+{
+    __try {
+        EnterCriticalSection (__mutex);
+    }
+    __except (1) {
+        return -1;
+    }
+    return 0;
+}
+
+inline int __rw_mutex_unlock (_RWSTD_CRITICAL_SECTION *__mutex)
+{
+    __try {
+        LeaveCriticalSection (__mutex);
+    }
+    __except (1) {
+        return -1;
+    }
+    return 0;
+}
+
+#define _RWSTD_MUTEX_INIT(mutex)      \
+   __rw_mutex_init (_RWSTD_REINTERPRET_CAST (_RWSTD_CRITICAL_SECTION*, &mutex))
+#define _RWSTD_MUTEX_DESTROY(mutex)   \
+   __rw_mutex_destroy (_RWSTD_REINTERPRET_CAST (_RWSTD_CRITICAL_SECTION*, &mutex))
+#define _RWSTD_MUTEX_LOCK(mutex)      \
+   __rw_mutex_lock (_RWSTD_REINTERPRET_CAST (_RWSTD_CRITICAL_SECTION*, &mutex))
+#define _RWSTD_MUTEX_UNLOCK(mutex)    \
+   __rw_mutex_unlock (_RWSTD_REINTERPRET_CAST (_RWSTD_CRITICAL_SECTION*, &mutex))
+
+#ifndef _MSC_VER
+#  undef __try
+#  undef __except
+#endif   // _MSC_VER
+
+}   // namespace __rw
diff --git a/include/rw/_mutex.h b/include/rw/_mutex.h
index 2826dc6..9ba480d 100644
--- a/include/rw/_mutex.h
+++ b/include/rw/_mutex.h
@@ -1,7 +1,6 @@
 /***************************************************************************
  *
- * _mutex.h - definitions of classes and inline functions
- *            for thread safety and atomic operations
+ * _mutex.h - definitions of classes for thread safety
  *
  * This is an internal header file used to implement the C++ Standard
  * Library. It should never be #included directly by a program.
@@ -44,316 +43,45 @@
 #endif   // _RWSTD_RW_DEFS_H_INCLUDED
 
 
+#ifndef _RWSTD_RW_ATOMIC_H_INCLUDED
+#  include <rw/_atomic.h>
+#endif   // _RWSTD_RW_ATOMIC_H_INCLUDED
+
+
 #ifdef _RWSTD_REENTRANT
 
-#ifndef _RWSTD_RW_EXCEPTION_H_INCLUDED
-#  include <rw/_exception.h>
-#endif   // _RWSTD_RW_EXCEPTION_INCLUDED
+#  ifndef _RWSTD_RW_EXCEPTION_H_INCLUDED
+#    include <rw/_exception.h>
+#  endif   // _RWSTD_RW_EXCEPTION_INCLUDED
 
-#ifndef _RWSTD_RW_ERROR_H_INCLUDED
-#  include <rw/_error.h>
-#endif   // _RWSTD_RW_ERROR_H_INCLUDED
+#  ifndef _RWSTD_RW_ERROR_H_INCLUDED
+#    include <rw/_error.h>
+#  endif   // _RWSTD_RW_ERROR_H_INCLUDED
 
 
 // work around SunOS 5.{8,9}/SunPro bug (see PR #26255)
-#if defined (__SunOS_5_8) || defined (__SunOS_5_9)
-#  undef _TIME_T
-#endif   // __SunOS_5_{8,9}
+#  if defined (__SunOS_5_8) || defined (__SunOS_5_9)
+#    undef _TIME_T
+#  endif   // __SunOS_5_{8,9}
 
-#if defined (_RWSTD_SOLARIS_THREADS)  // assuming Solaris 2.1 or greater
-
-// SunOS 5.7 Threads Library:
-//   "A statically  allocated  mutex does  not  need to be explicitly
-//   initialized; by default, a statically allocated mutex is initialized
-//   with  all  zeros and its scope is set to be within the calling
-//   process."
-
-#  include <synch.h>
-#  include <thread.h>
-
-#  define _RWSTD_MUTEX_INIT(mutex)      mutex_init (&mutex, USYNC_THREAD, 0)
-#  define _RWSTD_MUTEX_DESTROY(mutex)   mutex_destroy (&mutex)
-#  define _RWSTD_MUTEX_LOCK(mutex)      mutex_lock (&mutex)
-#  define _RWSTD_MUTEX_UNLOCK(mutex)    mutex_unlock (&mutex)
-#  define _RWSTD_MUTEX_T                mutex_t
-
-#elif defined (_RWSTD_POSIX_THREADS)
-
-#  if    defined (_RWSTD_EDG_ECCP) && defined (_RWSTD_OS_LINUX) \
-      && defined (_RWSTD_NO_LONG_LONG)
-     // disable error #450-D: the type "long long" is nonstandard
-     // when using the vanilla EDG eccp in strict mode (i.e., w/o
-     // long long support)
-#    pragma diag_suppress 450
-#  endif   // EDG eccp on Linux
-
-// LinuxThreads man page:
-//   "Variables of type pthread_mutex_t can also be initialized
-//    statically, using the constants  PTHREAD_MUTEX_INITIALIZER
-//    (for fast mutexes), PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
-//    (for recursive mutexes), and PTHREAD_ERRORCHECK_MUTEX_INI-
-//    TIALIZER_NP (for error checking mutexes)."
-//    ...
-//    "Attempting to initialize an already initialized mutex results
-//    in undefined behavior."
-
-#  include <pthread.h>
-
-#  define _RWSTD_MUTEX_INIT(mutex)      pthread_mutex_init (&mutex, 0)
-#  define _RWSTD_MUTEX_DESTROY(mutex)   pthread_mutex_destroy (&mutex)
-#  define _RWSTD_MUTEX_LOCK(mutex)      pthread_mutex_lock (&mutex)
-#  define _RWSTD_MUTEX_UNLOCK(mutex)    pthread_mutex_unlock (&mutex)
-#  define _RWSTD_MUTEX_T                pthread_mutex_t
-
-#elif defined (_RWSTD_DCE_THREADS)
-
-#  if defined (_RWSTD_NO_DCE_PTHREAD_H)
-#    include <pthread.h>
+#  if defined (_RWSTD_SOLARIS_THREADS)  // assuming Solaris 2.1 or greater
+#    include <rw/_mutex-solaris.h>
+#  elif defined (_RWSTD_POSIX_THREADS)
+#    include <rw/_mutex-pthread.h>
+#  elif defined (_RWSTD_DCE_THREADS)
+#    include <rw/_mutex-dce.h>
+#  elif defined (_WIN32)
+#    include <rw/_mutex-win32.h>
+#  elif defined (__OS2__)
+#    include <rw/_mutex-os2.h>
 #  else
-#    include <dce/pthread.h>
+#    error unknown thread environment
 #  endif
 
-#  define _RWSTD_MUTEX_INIT(mutex) \
-          pthread_mutex_init (&mutex, pthread_mutexattr_default)
-#  define _RWSTD_MUTEX_DESTROY(mutex)   pthread_mutex_destroy (&mutex)
-#  define _RWSTD_MUTEX_LOCK(mutex)      pthread_mutex_lock (&mutex)
-#  define _RWSTD_MUTEX_UNLOCK(mutex)    pthread_mutex_unlock (&mutex)
-#  define _RWSTD_MUTEX_T                pthread_mutex_t
 
-#elif defined (_WIN32)
-
-#  ifdef __MINGW32__
-#    define _RWSTD_CRITICAL_SECTION _CRITICAL_SECTION
-#  else
-#    define _RWSTD_CRITICAL_SECTION _RTL_CRITICAL_SECTION
-#  endif
-
-#  ifdef _RWSTD_NO_FWD_DECLARATIONS
-
-     // #including <windows.h> without WIN32_LEAN_AND_MEAN macro defined
-     // may cause an errors "WinSock.h has already been included"
-     // when <winsock2.h> has been included after this header
-#    include <windows.h>
-#    define _RWSTD_MUTEX_T _RWSTD_CRITICAL_SECTION
-
-#  else   // if !defined (_RWSTD_NO_FWD_DECLARATIONS)
-
-   // avoid #including this header (MFC doesn't like it)
-   // #  include <windows.h>
-
-extern "C" {
-
-// but rather declare these globals here
-struct _RWSTD_CRITICAL_SECTION;
-
-__declspec (dllimport) void __stdcall
-InitializeCriticalSection (_RWSTD_CRITICAL_SECTION*);
-
-__declspec (dllimport) void __stdcall
-EnterCriticalSection (_RWSTD_CRITICAL_SECTION*);
-
-__declspec (dllimport) void __stdcall
-LeaveCriticalSection (_RWSTD_CRITICAL_SECTION*);
-
-__declspec (dllimport) void __stdcall
-DeleteCriticalSection (_RWSTD_CRITICAL_SECTION*);
-
-#    if defined (_RWSTD_INTERLOCKED_T) && !defined (_MSC_VER)
-
-__declspec (dllimport) long __stdcall
-InterlockedIncrement (_RWSTD_INTERLOCKED_T*);
-
-__declspec (dllimport) long __stdcall
-InterlockedDecrement (_RWSTD_INTERLOCKED_T*);
-
-__declspec (dllimport) long __stdcall
-InterlockedExchange (_RWSTD_INTERLOCKED_T*, long);
-
-#    endif   // _RWSTD_INTERLOCKED_T && !_MSC_VER
-
-}   // extern "C"
-
-_RWSTD_NAMESPACE (__rw) { 
-
-// fake critical section type
-union __rw_critical_section {
-    long _C_pad;   // force alignment
-
-#    ifndef _WIN64
-    char _C_buf [24 /* == sizeof (_RTL_CRITICAL_SECTION) */];
-#    else    // #ifdef _WIN64
-    char _C_buf [40 /* == sizeof (_RTL_CRITICAL_SECTION) */];
-#    endif   // _WIN64
-};
-
-#    define _RWSTD_MUTEX_T _RW::__rw_critical_section
-
-}   // namespace __rw
-
-
-#  endif   // _RWSTD_NO_FWD_DECLARATIONS
-
-#  ifdef _MSC_VER
-extern "C" long __cdecl _InterlockedIncrement (volatile long*);
-extern "C" long __cdecl _InterlockedDecrement (volatile long*);
-extern "C" long __cdecl _InterlockedExchange (volatile long*, long);
-#    ifdef _RWSTD_MSVC
-#      pragma intrinsic (_InterlockedIncrement)
-#      pragma intrinsic (_InterlockedDecrement)
-#      pragma intrinsic (_InterlockedExchange)
-#    endif   // _RWSTD_MSVC
-
-#    if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
-extern "C" short __cdecl _InterlockedIncrement16 (volatile short*);
-extern "C" short __cdecl _InterlockedDecrement16 (volatile short*);
-#      pragma intrinsic (_InterlockedIncrement16)
-#      pragma intrinsic (_InterlockedDecrement16)
-#    endif   // _RWSTD_MSVC >= 1400
-
-#    ifdef _M_X64
-extern "C" long long __cdecl _InterlockedIncrement64 (volatile long long*);
-extern "C" long long __cdecl _InterlockedDecrement64 (volatile long long*);
-extern "C" long long __cdecl _InterlockedExchange64 (volatile long long*,
-                                                     long long);
-#      ifdef _RWSTD_MSVC
-#        pragma intrinsic (_InterlockedIncrement64)
-#        pragma intrinsic (_InterlockedDecrement64)
-#        pragma intrinsic (_InterlockedExchange64)
-#      endif   // _RWSTD_MSVC
-#    endif   // _M_X64
-#  elif defined (_RWSTD_INTERLOCKED_T)
-
-inline long _InterlockedIncrement (volatile long *__x)
-{
-    return InterlockedIncrement (
-        _RWSTD_CONST_CAST (_RWSTD_INTERLOCKED_T*, __x));
-}
-
-inline long _InterlockedDecrement (volatile long *__x)
-{
-    return InterlockedDecrement (
-        _RWSTD_CONST_CAST (_RWSTD_INTERLOCKED_T*, __x));
-}
-
-inline long _InterlockedExchange (volatile long *__x, long __y)
-{
-    return InterlockedExchange (
-        _RWSTD_CONST_CAST (_RWSTD_INTERLOCKED_T*, __x), __y);
-}
-
-#  endif   // _MSC_VER
-
-
-_RWSTD_NAMESPACE (__rw) { 
-
-#  ifndef _MSC_VER
-#    define __try               if (1)
-#    define __except(ignore)    else if (0)
-#  endif   // _MSC_VER
-
-// Win32/64 throws non-C++ exceptions rather than returning error status
-// from some system calls like most other operating systems do
-
-inline int __rw_mutex_init (_RWSTD_CRITICAL_SECTION *__mutex)
-{
-    __try {
-        InitializeCriticalSection (__mutex);
-    }
-    __except (1) {
-        return -1;
-    }
-    return 0;
-}
-
-inline int __rw_mutex_destroy (_RWSTD_CRITICAL_SECTION *__mutex)
-{
-    __try {
-        DeleteCriticalSection (__mutex);
-    }
-    __except (1) {
-        return -1;
-    }
-    return 0;
-}
-
-inline int __rw_mutex_lock (_RWSTD_CRITICAL_SECTION *__mutex)
-{
-    __try {
-        EnterCriticalSection (__mutex);
-    }
-    __except (1) {
-        return -1;
-    }
-    return 0;
-}
-
-inline int __rw_mutex_unlock (_RWSTD_CRITICAL_SECTION *__mutex)
-{
-    __try {
-        LeaveCriticalSection (__mutex);
-    }
-    __except (1) {
-        return -1;
-    }
-    return 0;
-}
-
-#  define _RWSTD_MUTEX_INIT(mutex)      \
-   __rw_mutex_init (_RWSTD_REINTERPRET_CAST (_RWSTD_CRITICAL_SECTION*, &mutex))
-#  define _RWSTD_MUTEX_DESTROY(mutex)   \
-   __rw_mutex_destroy (_RWSTD_REINTERPRET_CAST (_RWSTD_CRITICAL_SECTION*, &mutex))
-#  define _RWSTD_MUTEX_LOCK(mutex)      \
-   __rw_mutex_lock (_RWSTD_REINTERPRET_CAST (_RWSTD_CRITICAL_SECTION*, &mutex))
-#  define _RWSTD_MUTEX_UNLOCK(mutex)    \
-   __rw_mutex_unlock (_RWSTD_REINTERPRET_CAST (_RWSTD_CRITICAL_SECTION*, &mutex))
-
-#  ifndef _MSC_VER
-#    undef __try
-#    undef __except
-#  endif   // _MSC_VER
-
-}   // namespace __rw
-
-#elif defined (__OS2__)
-
-#  define INCL_DOSSEMAPHORES
-
-#  include <os2.h>
-
-#  define _RWSTD_MUTEX_INIT(mutex) \
-          DosCreateMutexSem (0, &mutex, DC_SEM_SHARED,FALSE)
-#  define _RWSTD_MUTEX_DESTROY(mutex)   DosCloseMutexSem (mutex)
-#  define _RWSTD_MUTEX_LOCK(mutex) \
-          DosRequestMutexSem (mutex, SEM_INDEFINITE_WAIT)
-#  define _RWSTD_MUTEX_UNLOCK(mutex)    DosReleaseMutexSem (mutex)
-#  define _RWSTD_MUTEX_T                HMTX
-
-#else
-#  error unknown thread environment
-#endif
-
-#if defined(_RWSTD_NO_STATIC_MUTEX_INIT)
-#  include <new>
-#endif  //_RWSTD_NO_STATIC_MUTEX_INIT
-
-
-#if defined (__GNUG__) && defined (__osf__)
-   // prevent g++ warnings about missing initializers
-   // see <pthread.h> for explanation of _PTHREAD_NOMETER_STATIC
-#  ifndef _PTHREAD_NOMETER_STATIC
-#    define _RWSTD_PTHREAD_MUTEX_INITIALIZER \
-            { _PTHREAD_MSTATE_SLOW, _PTHREAD_MVALID | _PTHREAD_MVF_STA, \
-              0, 0, 0, 0, 0, 0 }
-#  else   // if defined (_PTHREAD_NOMETER_STATIC)
-#    define _RWSTD_PTHREAD_MUTEX_INITIALIZER
-            { 0, _PTHREAD_MVALID | _PTHREAD_MVF_STA, 0, 0, 0, 0, 0, 0 }
-#  endif   // _PTHREAD_NOMETER_STATIC
-#elif defined (__GNUG__) && defined (__sgi__)
-   // prevent g++ warnings about a partly bracketed initializer
-#  define _RWSTD_PTHREAD_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
-#else
-#  define _RWSTD_PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
-#endif
+#  if defined(_RWSTD_NO_STATIC_MUTEX_INIT)
+#    include <new>
+#  endif  //_RWSTD_NO_STATIC_MUTEX_INIT
 
 
 _RWSTD_NAMESPACE (__rw) { 
@@ -382,19 +110,19 @@
 public:
 
     void _C_acquire () {
-#if !defined (__HP_aCC) || __HP_aCC > 32700
+#  if !defined (__HP_aCC) || __HP_aCC > 32700
         if (0 != _RWSTD_MUTEX_LOCK (_C_mutex))
             _RW::__rw_throw (_RWSTD_ERROR_RUNTIME_ERROR,
                              "synchronization error");
-#else
+#  else
         // working around an HP aCC 3.27 bug JAGac88738
         _RWSTD_MUTEX_LOCK (_C_mutex);
-#endif   // !defined (__HP_aCC) || __HP_aCC > 32700
+#  endif   // !defined (__HP_aCC) || __HP_aCC > 32700
     }
 
     void _C_release ();
 
-#ifdef _RWSTD_NO_STATIC_MUTEX_INIT
+#  ifdef _RWSTD_NO_STATIC_MUTEX_INIT
 
     // static initialization not an option, define ctor and dtor
     // and make member mutex private
@@ -409,7 +137,7 @@
     __rw_mutex_base (const __rw_mutex_base&);
     __rw_mutex_base& operator= (const __rw_mutex_base&);
 
-#endif   // _RWSTD_NO_STATIC_MUTEX_INIT
+#  endif   // _RWSTD_NO_STATIC_MUTEX_INIT
 
     _RWSTD_MUTEX_T _C_mutex;   // the real thing
 };
@@ -429,7 +157,7 @@
 {
 public:
 
-#ifndef _RWSTD_NO_STATIC_MUTEX_INIT
+#  ifndef _RWSTD_NO_STATIC_MUTEX_INIT
 
     __rw_mutex ();
 
@@ -441,12 +169,12 @@
     __rw_mutex (const __rw_mutex&);
     __rw_mutex& operator= (const __rw_mutex&);
 
-#endif   // _RWSTD_NO_STATIC_MUTEX_INIT
+#  endif   // _RWSTD_NO_STATIC_MUTEX_INIT
 
 };
 
 
-#ifndef _RWSTD_NO_STATIC_MUTEX_INIT
+#  ifndef _RWSTD_NO_STATIC_MUTEX_INIT
 
 // helper factory class - static member is guranteed to be constructed
 // during static initialization; objects of this POD class are not
@@ -462,14 +190,15 @@
 template <class _TypeT>
 __rw_mutex_base __rw_static_mutex<_TypeT>::_C_mutex
 
-#ifdef _RWSTD_POSIX_THREADS
+#    ifdef _RWSTD_MUTEX_INITIALIZER
 
-    = { _RWSTD_PTHREAD_MUTEX_INITIALIZER }
+    = { _RWSTD_MUTEX_INITIALIZER }
 
-#endif   // _RWSTD_POSIX_THREADS
+#      undef _RWSTD_MUTEX_INITIALIZER
+#    endif   // _RWSTD_MUTEX_INITIALIZER
         ;
 
-#if _RWSTD_INSTANTIATE (_STATIC_MUTEX, _INT)
+#    if _RWSTD_INSTANTIATE (_STATIC_MUTEX, _INT)
 
 // explicitly instantiated to work around a g++ 2.95.2 bug on COFF systems
 // (such as IBM AIX or DEC OSF1) where it "forgets" to do so implicitly for
@@ -477,30 +206,30 @@
 _RWSTD_INSTANTIATE_1 (class _RWSTD_TI_EXPORT __rw_static_mutex<int>);
 _RWSTD_INSTANTIATE_1 (class _RWSTD_TI_EXPORT __rw_static_mutex<size_t>);
 
-#endif   // _RWSTD_INSTANTIATE (_STATIC_MUTEX, _INT)
+#    endif   // _RWSTD_INSTANTIATE (_STATIC_MUTEX, _INT)
 
 
 inline __rw_mutex::__rw_mutex ()
 
-#else   // if defined (_RWSTD_NO_STATIC_MUTEX_INIT)
+#  else   // if defined (_RWSTD_NO_STATIC_MUTEX_INIT)
 
 inline __rw_mutex_base::__rw_mutex_base ()
 
-#endif   // _RWSTD_NO_STATIC_MUTEX_INIT
+#  endif   // _RWSTD_NO_STATIC_MUTEX_INIT
 { 
     if (0 != _RWSTD_MUTEX_INIT (_C_mutex))
         _RW::__rw_throw (_RWSTD_ERROR_RUNTIME_ERROR, "synchronization error");
 }
 
-#ifndef _RWSTD_NO_STATIC_MUTEX_INIT
+#  ifndef _RWSTD_NO_STATIC_MUTEX_INIT
 
 inline __rw_mutex::~__rw_mutex () 
 
-#else   // if defined (_RWSTD_NO_STATIC_MUTEX_INIT)
+#  else   // if defined (_RWSTD_NO_STATIC_MUTEX_INIT)
 
 inline __rw_mutex_base::~__rw_mutex_base () 
 
-#endif   // _RWSTD_NO_STATIC_MUTEX_INIT
+#  endif   // _RWSTD_NO_STATIC_MUTEX_INIT
 {
     _RWSTD_MUTEX_DESTROY (_C_mutex);
 }
@@ -516,7 +245,7 @@
 // function with a ptr to that type to obtain an initialized mutex object
 // that is the same for each unique type passed to the function
 
-#ifndef _RWSTD_NO_STATIC_MUTEX_INIT
+#  ifndef _RWSTD_NO_STATIC_MUTEX_INIT
 
 template <class _TypeT>
 inline
@@ -526,20 +255,20 @@
     return __rw_static_mutex<_TypeT>::_C_mutex;
 }
 
-#else   // if defined (_RWSTD_NO_STATIC_MUTEX_INIT)
+#  else   // if defined (_RWSTD_NO_STATIC_MUTEX_INIT)
 
-#ifdef _INLINE_WITH_STATICS
+#    ifdef _INLINE_WITH_STATICS
 
 template <class _TypeT>
 _INLINE_WITH_STATICS
 __rw_mutex_base& __rw_get_static_mutex (_TypeT*)
 
-#else    // if !defined (_INLINE_WITH_STATICS)
+#    else    // if !defined (_INLINE_WITH_STATICS)
 
 template <class _TypeT>
 __rw_mutex_base& __rw_get_static_mutex (_TypeT*)
 
-#endif   // _INLINE_WITH_STATICS
+#    endif   // _INLINE_WITH_STATICS
 
 {
     // allocate properly aligned memory for static mutex (necessary
@@ -564,15 +293,18 @@
     // implicit initialization used to prevent a g++ 2.95.2 warning on Tru64
     // sorry: semantics of inline function static data are wrong (you'll wind
     // up with multiple copies)
-    static volatile long __cntr /* = 0 */;   // initialization counter
+    static volatile int __cntr /* = 0 */;   // initialization counter
 
-#if defined (_WIN32)
+#    if !defined (_RWSTD_NO_ATOMIC_OPS) && !defined (_RWSTD_NO_INT_ATOMIC_OPS)
     // MT safe
-    if (0 == __cntr && 1 == _InterlockedIncrement ((long*)&__cntr))
-#else
+    // cast __cntr to int& (see STDCXX-792)
+    // casting should be removed after fixing STDCXX-794
+    if (0 == __cntr && 1 == _RWSTD_ATOMIC_PREINCREMENT (
+            _RWSTD_CONST_CAST (int&, __cntr), false))
+#    else   // _RWSTD_NO_ATOMIC_OPS || _RWSTD_NO_INT_ATOMIC_OPS
     // not so safe (volatile should help)
     if (0 == __cntr && 1 == ++__cntr)
-#endif   // _WIN32
+#    endif   // !_RWSTD_NO_ATOMIC_OPS && !_RWSTD_NO_INT_ATOMIC_OPS
 
     {
         // manually initialize `mutex' via a call to placement new
@@ -589,13 +321,13 @@
     return __mutex;
 }
 
-#endif   //_RWSTD_NO_STATIC_MUTEX_INIT
+#  endif   //_RWSTD_NO_STATIC_MUTEX_INIT
 
 
 // clean up
-#undef _RWSTD_MUTEX_LOCK
-#undef _RWSTD_MUTEX_UNLOCK
-#undef _RWSTD_MUTEX_T
+#  undef _RWSTD_MUTEX_LOCK
+#  undef _RWSTD_MUTEX_UNLOCK
+#  undef _RWSTD_MUTEX_T
 
 
 // allows safe use of a mutex in the presence of exceptions
@@ -653,1479 +385,19 @@
     }
 };
 
-
-// helper functions for atomic value [in|de]crement and exchange
-// the functions are atomic with respect to each other as long as
-// they are passed the same mutex by the callers
-template <class _TypeT>
-inline
-_TypeT __rw_atomic_preincrement (_TypeT &__t, __rw_mutex_base &__mutex)
-{
-    _RWSTD_MT_GUARD (__mutex);
-
-    return ++__t;
-}
-
-
-template <class _TypeT>
-inline
-_TypeT __rw_atomic_predecrement (_TypeT &__t, __rw_mutex_base &__mutex)
-{
-    _RWSTD_MT_GUARD (__mutex);
-
-    return --__t;
-}
-
-
-template <class _TypeT, class _TypeU>
-inline
-_TypeT __rw_atomic_exchange (_TypeT &__t, const _TypeU &__u,
-                             __rw_mutex_base &__mutex)
-{
-    _RWSTD_MT_GUARD (__mutex);
-
-    _TypeT __tmp = __t;
-
-#ifndef _WIN64
-    __t = __u;
-#else
-    // silence MSVC conversion warnings (cast breaks SunPro 5.3 and prior)
-    __t = _RWSTD_STATIC_CAST (_TypeT, __u);
-#endif
-
-    return __tmp;
-}
-
-
-// for use on class statics or on namespace-scope variables
-// the unused argument is only here so that all functions
-// can be called from the same set of macros
-
-template <class _TypeT>
-inline
-_TypeT __rw_atomic_preincrement (_TypeT &__t, bool)
-{
-    return __rw_atomic_preincrement (__t,
-                                     __rw_get_static_mutex ((_TypeT*)0));
-}
-
-
-template <class _TypeT>
-inline
-_TypeT __rw_atomic_predecrement (_TypeT &__t, bool)
-{
-    return __rw_atomic_predecrement (__t,
-                                     __rw_get_static_mutex ((_TypeT*)0));
-}
-
-
-template <class _TypeT, class _TypeU>
-inline
-_TypeT __rw_atomic_exchange (_TypeT &__t, const _TypeU &__u, bool)
-{
-    return __rw_atomic_exchange (__t, __u,
-                                 __rw_get_static_mutex ((_TypeT*)0));
-}
-
-/********************** no atomic ops ********************************/
-
-#if defined (_RWSTD_NO_ATOMIC_OPS)
-
-// do nothing
-
-/********************** DEC CXX **************************************/
-
-#elif defined (__DECCXX)
-
 }   // namespace __rw
 
-// get declarations of __ATOMIC_XXX intrinsics
-#  include <machine/builtins.h>
 
-_RWSTD_NAMESPACE (__rw) {
-
-// __ATOMIC_[DE|IN]CREMENT_[LONG|QUAD] and __ATOMIC_EXCH_[LONG|QUAD] are
-// intrinsic functions declared in <machine/builtins.h> that atomically
-// modify their argument and return its original value (__ATOMIC_XXX_LONG
-// is misnamed -- it actually operates on an int, not a long)
-
-inline int
-__rw_atomic_preincrement (int &__x, bool)
-{
-    return 1 + __ATOMIC_INCREMENT_LONG (&__x);
-}
-
-
-inline unsigned
-__rw_atomic_preincrement (unsigned &__x, bool)
-{
-    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (int&, __x),
-                                     false);
-}
-
-
-inline long
-__rw_atomic_preincrement (long &__x, bool)
-{
-    return 1 + __ATOMIC_INCREMENT_QUAD (&__x);
-}
-
-
-inline unsigned long
-__rw_atomic_preincrement (unsigned long &__x, bool)
-{
-    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (long&, __x),
-                                     false);
-}
-
-
-inline int
-__rw_atomic_predecrement (int &__x, bool)
-{
-    return __ATOMIC_DECREMENT_LONG (&__x) - 1;
-}
-
-
-inline unsigned
-__rw_atomic_predecrement (unsigned &__x, bool)
-{
-    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (int&, __x),
-                                     false);
-}
-
-
-inline long
-__rw_atomic_predecrement (long &__x, bool)
-{
-    return __ATOMIC_DECREMENT_QUAD (&__x) - 1;
-}
-
-
-inline unsigned long
-__rw_atomic_predecrement (unsigned long &__x, bool)
-{
-    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (long&, __x),
-                                     false);
-}
-
-
-inline int
-__rw_atomic_exchange (int &__x, int __y, bool)
-{
-    return __ATOMIC_EXCH_LONG (&__x, __y);
-}
-
-
-inline unsigned
-__rw_atomic_exchange (unsigned &__x, unsigned __y, bool)
-{
-    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (unsigned&, __x),
-                                 _RWSTD_STATIC_CAST (int, __y), false);
-}
-
-
-inline long
-__rw_atomic_exchange (long &__x, long __y, bool)
-{
-    return __ATOMIC_EXCH_QUAD (&__x, __y);
-}
-
-
-inline unsigned long
-__rw_atomic_exchange (unsigned long &__x, unsigned long __y, bool)
-{
-    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (long&, __x),
-                                 _RWSTD_STATIC_CAST (long, __y), false);
-}
-
-/********************** SPARC **************************************/
-
-#elif defined (__sparc) && (defined (__SUNPRO_CC) || defined (__GNUG__))
-
-extern "C" {
-
-// define in assembler file "atomic-sparc.s" and "atomic-sparc64.s"
-// exchange returns the original value, and add returns the incremented
-// value
-
-int  __rw_atomic_xchg32 (int*, int);
-int  __rw_atomic_add32 (int*, int);
-
-#  if defined (_LP64)
-
-long __rw_atomic_xchg64 (long*, long);
-long __rw_atomic_add64 (long*, long);
-
-#  endif   // !_LP64
-
-}   // extern "C"
-
-
-inline int
-__rw_atomic_preincrement (int &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
-    return __rw_atomic_add32 (&__x, 1);
-}
-
-
-inline unsigned
-__rw_atomic_preincrement (unsigned &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned));
-    return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (int*, &__x), 1);
-}
-
-
-inline int
-__rw_atomic_predecrement (int &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
-    return __rw_atomic_add32 (&__x, -1);
-}
-
-
-inline unsigned
-__rw_atomic_predecrement (unsigned &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned));
-    return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (int*, &__x), -1);
-}
-
-
-inline int
-__rw_atomic_exchange (int &__x, int __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
-    return __rw_atomic_xchg32 (&__x, __y);
-}
-
-
-inline unsigned
-__rw_atomic_exchange (unsigned &__x, unsigned __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned));
-    return __rw_atomic_xchg32 (_RWSTD_REINTERPRET_CAST (int*, &__x),
-                               _RWSTD_STATIC_CAST (int, __y));
-}
-
-#  if _RWSTD_INT_SIZE < _RWSTD_LONG_SIZE
-
-inline long
-__rw_atomic_preincrement (long &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
-    return __rw_atomic_add64 (&__x, 1);
-}
-
-
-inline unsigned long
-__rw_atomic_preincrement (unsigned long &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
-    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (long*, &__x), 1);
-}
-
-
-
-inline long
-__rw_atomic_predecrement (long &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
-    return __rw_atomic_add64 (&__x, -1);
-}
-
-
-inline unsigned long
-__rw_atomic_predecrement (unsigned long &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
-    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (long*, &__x), -1);
-}
-
-
-inline long
-__rw_atomic_exchange (long &__x, long __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
-    return __rw_atomic_xchg64 (&__x, __y);
-}
-
-
-inline unsigned long
-__rw_atomic_exchange (unsigned long &__x, unsigned long __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
-    return __rw_atomic_xchg64 (_RWSTD_REINTERPRET_CAST (long*, &__x),
-                               _RWSTD_STATIC_CAST (long, __y));
-}
-
-#  endif   // _RWSTD_INT_SIZE < _RWSTD_LONG_SIZE
-
-/********************** AIX **************************************/
-
-#elif defined (_AIX43) && defined (__IBMCPP__)
-
-}   // namespace __rw
-
-#include <sys/atomic_op.h>
-
-_RWSTD_NAMESPACE (__rw) {
-
-inline int
-__rw_atomic_preincrement (int &__x, bool)
-{
-    return fetch_and_add (&__x, 1) + 1;
-}
-
-
-inline unsigned
-__rw_atomic_preincrement (unsigned &__x, bool)
-{
-    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (int&, __x),
-                                     false);
-}
-
-
-inline int
-__rw_atomic_predecrement (int &__x, bool)
-{
-    return fetch_and_add(&__x,-1) - 1;
-}
-
-
-inline unsigned
-__rw_atomic_predecrement (unsigned &__x, bool)
-{
-    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (int&, __x),
-                                     false);
-}
-
-
-inline int
-__rw_atomic_exchange (int &__x, int __y, bool)
-{
-    int __tmp;
-
-    do {
-        __tmp = __x;
-    } while (!compare_and_swap (&__x, &__tmp, __y));
-
-    return __tmp;
-}
-
-
-inline unsigned
-__rw_atomic_exchange (unsigned &__x, unsigned __y, bool)
-{
-    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (int&, __x),
-                                 _RWSTD_STATIC_CAST (int, __y), false);
-}
-
-
-#  if _RWSTD_INT_SIZE < _RWSTD_LONG_SIZE
-
-inline long
-__rw_atomic_preincrement (long &__x, bool)
-{
-    return fetch_and_addlp (&__x, 1) + 1;
-}
-
-
-inline unsigned long
-__rw_atomic_preincrement (unsigned long &__x, bool)
-{
-  return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (long&, __x),
-                                   false);
-}
-
-
-inline long
-__rw_atomic_predecrement (long &__x, bool)
-{
-    return fetch_and_addlp (&__x, -1) - 1;
-}
-
-
-inline unsigned long
-__rw_atomic_predecrement (unsigned long &__x, bool)
-{
-    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (long&, __x),
-                                     false);
-}
-
-
-inline long
-__rw_atomic_exchange (long &__x, long __y, bool)
-{
-    long __tmp;
-
-    do {
-        __tmp = __x;
-    } while (!compare_and_swaplp (&__x, &__tmp, __y));
-
-    return __tmp;
-}
-
-
-inline unsigned long
-__rw_atomic_exchange (unsigned long &__x, unsigned long __y, bool)
-{
-    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (long&, __x),
-                                 _RWSTD_STATIC_CAST (long, __y), false);
-}
-
-#  endif   // _RWSTD_INT_SIZE < _RWSTD_LONG_SIZE
-
-
-/********************** SGI **************************************/
-
-#elif defined (__sgi) && defined (__host_mips)
-
-}   // namespace __rw
-
-#  include <mutex.h>
-
-_RWSTD_NAMESPACE (__rw) {
-
-
-inline unsigned
-__rw_atomic_preincrement (unsigned &__x, bool)
-{
-    return __add_then_test32 (&__x, 1U);
-}
-
-
-inline int
-__rw_atomic_preincrement (int &__x, bool)
-{
-    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (unsigned&, __x),
-                                     false);
-}
-
-
-inline unsigned
-__rw_atomic_predecrement (unsigned &__x, bool)
-{
-    return __add_then_test32 (&__x, unsigned (-1));
-}
-
-
-inline int
-__rw_atomic_predecrement (int &__x, bool)
-{
-    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (unsigned &, __x),
-                                     false);
-}
-
-
-inline unsigned
-__rw_atomic_exchange (unsigned &__x, unsigned __y, bool)
-{
-    return __test_and_set32 (&__x, __y);
-}
-
-
-inline int
-__rw_atomic_exchange (int &__x, int __y, bool)
-{
-    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (unsigned int&, __x),
-                                 _RWSTD_STATIC_CAST (unsigned int, __y), false);
-}
-
-
-#  if _RWSTD_INT_SIZE < _RWSTD_LONG_SIZE
-
-inline unsigned long
-__rw_atomic_preincrement (unsigned long &__x, bool)
-{
-    return __add_then_test (&__x, 1);
-}
-
-
-inline long
-__rw_atomic_preincrement (long &__x, bool)
-{
-    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST(unsigned long&,
-                                                             __x),
-                                     false);
-}
-
-inline unsigned long
-__rw_atomic_predecrement (unsigned long &__x, bool)
-{
-    return __add_then_test (&__x, -1);
-}
-
-
-inline long
-__rw_atomic_predecrement (long &__x, bool)
-{
-    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (unsigned long&,
-                                                              __x),
-                                     false);
-}
-
-
-inline unsigned long
-__rw_atomic_exchange (unsigned long &__x, unsigned long __y, bool)
-{
-    return __test_and_set (&__x, __y);
-}
-
-
-inline long
-__rw_atomic_exchange (long &__x, long __y, bool)
-{
-    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (unsigned long&, __x),
-                                 _RWSTD_STATIC_CAST (unsigned long, __y),
-                                 false);
-}
-
-#  endif   // _RWSTD_INT_SIZE < _RWSTD_LONG_SIZE
-
-/********************** PA-RISC 2.0 ************************************/
-
-#elif defined (_PA_RISC2_0)
-
-extern "C" {
-
-// special constraint: the value of both the argument and the result
-// must not be zero
-
-int __rw_atomic_incr32 (int*);
-int __rw_atomic_decr32 (int*);
-int __rw_atomic_xchg32 (int*, int);
-
-}   // extern "C"
-
-
-inline int
-__rw_string_atomic_preincrement (int &__x, bool)
-{
-    return  __rw_atomic_incr32 (&__x);
-}
-
-
-inline unsigned
-__rw_string_atomic_preincrement (unsigned &__x, bool)
-{
-  
-    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST(int&, __x),
-                                     false);
-}
-
-
-inline int
-__rw_string_atomic_predecrement (int &__x, bool)
-{
-    return  __rw_atomic_decr32 (&__x);
-}
-
-
-inline unsigned
-__rw_string_atomic_predecrement (unsigned &__x, bool)
-{
-  
-    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST(int&, __x),
-                                     false);
-}
-
-
-inline int
-__rw_string_atomic_exchange (int &__x, int __y, bool)
-{
-    return __rw_atomic_xchg32 (&__x, __y);
-}
-
-
-inline unsigned
-__rw_string_atomic_exchange (unsigned &__x, unsigned __y, bool)
-{
-    return __rw_string_atomic_exchange (_RWSTD_REINTERPRET_CAST(int&, __x),
-                                        _RWSTD_STATIC_CAST(int,__y),
-                                        false);
-} 
-
-/********************** i386/gcc || _M_IX86 *********************************/
-
-#elif defined (__i386__) && (defined (__GNUG__) \
-   || defined (__INTEL_COMPILER)) || defined (_M_IX86)
-
-extern "C" {
-
-_RWSTD_EXPORT char __rw_atomic_add8 (char*, int);
-_RWSTD_EXPORT short __rw_atomic_add16 (short*, short);
-_RWSTD_EXPORT int __rw_atomic_add32 (int*, int);
-
-_RWSTD_EXPORT char __rw_atomic_xchg8 (char*, char);
-_RWSTD_EXPORT short __rw_atomic_xchg16 (short*, short);
-_RWSTD_EXPORT int __rw_atomic_xchg32 (int*, int);
-
-}   // extern "C"
-
-
-inline char
-__rw_atomic_preincrement (char &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
-    return __rw_atomic_add8 (&__x, +1);
-}
-
-
-inline signed char
-__rw_atomic_preincrement (signed char &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
-    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (char*, &__x), +1);
-}
-
-
-inline unsigned char
-__rw_atomic_preincrement (unsigned char &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
-    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (char*, &__x), +1);
-}
-
-
-inline short
-__rw_atomic_preincrement (short &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
-
-#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
-    return _InterlockedIncrement16 (&__x);
-#else
-    return __rw_atomic_add16 (&__x, +1);
-#endif
-}
-
-
-inline unsigned short
-__rw_atomic_preincrement (unsigned short &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
-
-#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
-    return _InterlockedIncrement16 (_RWSTD_REINTERPRET_CAST (short*, &__x));
-#else
-    return __rw_atomic_add16 (_RWSTD_REINTERPRET_CAST (short*, &__x), +1);
-#endif
-}
-
-
-inline int
-__rw_atomic_preincrement (int &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
-
-#ifdef _MSC_VER
-    return _InterlockedIncrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
-#else
-    return __rw_atomic_add32 (&__x, 1);
-#endif
-}
-
-
-inline unsigned int
-__rw_atomic_preincrement (unsigned int &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
-
-#ifdef _MSC_VER
-    return _InterlockedIncrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
-#else
-    return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (int*, &__x), 1);
-#endif
-}
-
-
-inline char
-__rw_atomic_predecrement (char &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
-    return __rw_atomic_add8 (&__x, -1);
-}
-
-
-inline signed char
-__rw_atomic_predecrement (signed char &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
-    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (char*, &__x), -1);
-}
-
-
-inline unsigned char
-__rw_atomic_predecrement (unsigned char &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
-    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (char*, &__x), -1);
-}
-
-
-inline short
-__rw_atomic_predecrement (short &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
-
-#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
-    return _InterlockedDecrement16 (&__x);
-#else
-    return __rw_atomic_add16 (&__x, -1);
-#endif
-}
-
-
-inline unsigned short
-__rw_atomic_predecrement (unsigned short &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
-
-#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
-    return _InterlockedDecrement16 (_RWSTD_REINTERPRET_CAST (short*, &__x));
-#else
-    return __rw_atomic_add16 (_RWSTD_REINTERPRET_CAST (short*, &__x), -1);
-#endif
-}
-
-
-inline int
-__rw_atomic_predecrement (int &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
-
-#ifdef _MSC_VER
-    return _InterlockedDecrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
-#else
-    return __rw_atomic_add32 (&__x, -1);
-#endif
-}
-
-
-inline unsigned int
-__rw_atomic_predecrement (unsigned int &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
-
-#ifdef _MSC_VER
-    return _InterlockedDecrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
-#else
-    return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (int*, &__x), -1);
-#endif
-}
-
-
-inline char
-__rw_atomic_exchange (char &__x, char __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
-    return __rw_atomic_xchg8 (&__x, __y);
-}
-
-
-inline signed char
-__rw_atomic_exchange (signed char &__x, signed char __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
-    return __rw_atomic_xchg8 (_RWSTD_REINTERPRET_CAST (char*, &__x),
-                              _RWSTD_STATIC_CAST (char, __y));
-}
-
-
-inline unsigned char
-__rw_atomic_exchange (unsigned char &__x, unsigned char __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
-    return __rw_atomic_xchg8 (_RWSTD_REINTERPRET_CAST (char*, &__x),
-                              _RWSTD_STATIC_CAST (char, __y));
-}
-
-
-inline short
-__rw_atomic_exchange (short &__x, short __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
-    return __rw_atomic_xchg16 (&__x, __y);
-}
-
-
-inline unsigned short
-__rw_atomic_exchange (unsigned short &__x, unsigned short __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
-    return __rw_atomic_xchg16 (_RWSTD_REINTERPRET_CAST (short*, &__x),
-                               _RWSTD_STATIC_CAST (short, __y));
-}
-
-
-inline int
-__rw_atomic_exchange (int &__x, int __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
-
-#ifdef _MSC_VER
-    return _InterlockedExchange (_RWSTD_REINTERPRET_CAST (long*, &__x),
-                                 _RWSTD_STATIC_CAST (long, __y));
-#else
-    return __rw_atomic_xchg32 (&__x, __y);
-#endif
-}
-
-
-inline unsigned int
-__rw_atomic_exchange (unsigned int &__x, unsigned int __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
-
-#ifdef _MSC_VER
-    return _InterlockedExchange (_RWSTD_REINTERPRET_CAST (long*, &__x),
-                                 _RWSTD_STATIC_CAST (long, __y));
-#else
-    return __rw_atomic_xchg32 (_RWSTD_REINTERPRET_CAST (int*, &__x),
-                               _RWSTD_STATIC_CAST (int, __y));
-#endif
-}
-
-/********************** IA64/x86_64/_M_X64 *****************************/
-
-#elif defined (__ia64) || defined (__x86_64) || defined (_M_X64)
-
-extern "C" {
-
-_RWSTD_EXPORT _RWSTD_INT8_T
-__rw_atomic_xchg8  (_RWSTD_INT8_T*,  _RWSTD_INT8_T);
-
-_RWSTD_EXPORT _RWSTD_INT16_T
-__rw_atomic_xchg16 (_RWSTD_INT16_T*, _RWSTD_INT16_T);
-
-_RWSTD_EXPORT _RWSTD_INT32_T
-__rw_atomic_xchg32 (_RWSTD_INT32_T*, _RWSTD_INT32_T);
-
-
-_RWSTD_EXPORT _RWSTD_INT8_T
-__rw_atomic_add8  (_RWSTD_INT8_T*,  _RWSTD_INT8_T);
-
-_RWSTD_EXPORT _RWSTD_INT16_T
-__rw_atomic_add16 (_RWSTD_INT16_T*, _RWSTD_INT16_T);
-
-_RWSTD_EXPORT _RWSTD_INT32_T
-__rw_atomic_add32 (_RWSTD_INT32_T*, _RWSTD_INT32_T);
-
-#ifdef _RWSTD_INT64_T
-
-_RWSTD_EXPORT _RWSTD_INT64_T
-__rw_atomic_xchg64 (_RWSTD_INT64_T*, _RWSTD_INT64_T);
-
-_RWSTD_EXPORT _RWSTD_INT64_T
-__rw_atomic_add64 (_RWSTD_INT64_T*, _RWSTD_INT64_T);
-
-#endif   // _RWSTD_INT64_T
-
-}   // extern "C"
-
-
-inline char
-__rw_atomic_preincrement (char &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
-
-    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
-                             +1);
-}
-
-
-inline signed char
-__rw_atomic_preincrement (signed char &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
-
-    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
-                             +1);
-}
-
-
-inline unsigned char
-__rw_atomic_preincrement (unsigned char &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
-
-    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
-                             +1);
-}
-
-
-inline short
-__rw_atomic_preincrement (short &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
-
-#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
-    return _InterlockedIncrement16 (&__x);
-#else
-    return __rw_atomic_add16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
-                              +1);
-#endif
-}
-
-
-inline unsigned short
-__rw_atomic_preincrement (unsigned short &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
-
-#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
-    return _InterlockedIncrement16 (_RWSTD_REINTERPRET_CAST (short*, &__x));
-#else
-    return __rw_atomic_add16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
-                              +1);
-#endif
-}
-
-
-inline int
-__rw_atomic_preincrement (int &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
-
-#ifdef _MSC_VER
-    return _InterlockedIncrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
-#else
-    return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
-                              +1);
-#endif
-}
-
-
-inline unsigned int
-__rw_atomic_preincrement (unsigned int &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
-
-#ifdef _MSC_VER
-    return _InterlockedIncrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
-#else
-    return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
-                              +1);
-#endif
-}
-
-
-#if 4 < _RWSTD_LONG_SIZE
-
-inline long
-__rw_atomic_preincrement (long &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
-
-    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
-                              +1);
-}
-
-
-inline unsigned long
-__rw_atomic_preincrement (unsigned long &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
-
-    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
-                              +1);
-}
-
-#endif   // _RWSTD_LONG_SIZE
-
-
-#ifdef _RWSTD_LONG_LONG
-#  if _RWSTD_LLONG_SIZE > _RWSTD_LONG_SIZE
-
-inline _RWSTD_LONG_LONG
-__rw_atomic_preincrement (_RWSTD_LONG_LONG &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (_RWSTD_LONG_LONG));
-
-#ifdef _MSC_VER
-    return _InterlockedIncrement64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x));
-#else
-    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
-                              +1);
-#endif
-}
-
-
-inline unsigned _RWSTD_LONG_LONG
-__rw_atomic_preincrement (unsigned _RWSTD_LONG_LONG &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned _RWSTD_LONG_LONG));
-
-#ifdef _MSC_VER
-    return _InterlockedIncrement64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x));
-#else
-    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
-                              +1);
-#endif
-}
-
-#  endif   // _RWSTD_LLONG_SIZE > _RWSTD_LONG_SIZE
-#endif   // _RWSTD_LONG_LONG
-
-
-inline char
-__rw_atomic_predecrement (char &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
-
-    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
-                             -1);
-}
-
-
-inline signed char
-__rw_atomic_predecrement (signed char &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
-
-    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
-                             -1);
-}
-
-
-inline unsigned char
-__rw_atomic_predecrement (unsigned char &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
-
-    return __rw_atomic_add8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
-                             -1);
-}
-
-
-inline short
-__rw_atomic_predecrement (short &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
-
-#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
-    return _InterlockedDecrement16 (&__x);
-#else
-    return __rw_atomic_add16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
-                              -1);
-#endif
-}
-
-
-inline unsigned short
-__rw_atomic_predecrement (unsigned short &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
-
-#if defined (_RWSTD_MSVC) && _RWSTD_MSVC >= 1400
-    return _InterlockedDecrement16 (_RWSTD_REINTERPRET_CAST (short*, &__x));
-#else
-    return __rw_atomic_add16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
-                              -1);
-#endif
-}
-
-
-inline int
-__rw_atomic_predecrement (int &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
-
-#ifdef _MSC_VER
-    return _InterlockedDecrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
-#else
-    return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
-                              -1);
-#endif
-}
-
-
-inline unsigned int
-__rw_atomic_predecrement (unsigned int &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
-
-#ifdef _MSC_VER
-    return _InterlockedDecrement (_RWSTD_REINTERPRET_CAST (long*, &__x));
-#else
-    return __rw_atomic_add32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
-                              -1);
-#endif
-}
-
-
-#if 4 < _RWSTD_LONG_SIZE
-
-inline long
-__rw_atomic_predecrement (long &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
-
-    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
-                              -1);
-}
-
-
-inline unsigned long
-__rw_atomic_predecrement (unsigned long &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
-
-    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
-                              -1);
-}
-
-#endif   // _RWSTD_LONG_SIZE
-
-
-#ifdef _RWSTD_LONG_LONG
-#  if _RWSTD_LLONG_SIZE > _RWSTD_LONG_SIZE
-
-inline _RWSTD_LONG_LONG
-__rw_atomic_predecrement (_RWSTD_LONG_LONG &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (_RWSTD_LONG_LONG));
-
-#ifdef _MSC_VER
-    return _InterlockedDecrement64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x));
-#else
-    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
-                              -1);
-#endif
-}
-
-
-inline unsigned _RWSTD_LONG_LONG
-__rw_atomic_predecrement (unsigned _RWSTD_LONG_LONG &__x, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned _RWSTD_LONG_LONG));
-
-#ifdef _MSC_VER
-    return _InterlockedDecrement64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x));
-#else
-    return __rw_atomic_add64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
-                              -1);
-#endif
-}
-
-#  endif   // _RWSTD_LLONG_SIZE > _RWSTD_LONG_SIZE
-#endif   // _RWSTD_LONG_LONG
-
-
-inline char
-__rw_atomic_exchange (char &__x, char __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (char));
-
-    return __rw_atomic_xchg8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
-                              _RWSTD_STATIC_CAST (_RWSTD_INT8_T, __y));
-}
-
-
-inline signed char
-__rw_atomic_exchange (signed char &__x, signed char __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (signed char));
-
-    return __rw_atomic_xchg8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
-                              _RWSTD_STATIC_CAST (_RWSTD_INT8_T, __y));
-}
-
-
-inline unsigned char
-__rw_atomic_exchange (unsigned char &__x, unsigned char __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (1 == sizeof (unsigned char));
-
-    return __rw_atomic_xchg8 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT8_T*, &__x),
-                              _RWSTD_STATIC_CAST (_RWSTD_INT8_T, __y));
-}
-
-
-inline short
-__rw_atomic_exchange (short &__x, short __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (2 == sizeof (short));
-
-    return __rw_atomic_xchg16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
-                               _RWSTD_STATIC_CAST (_RWSTD_INT16_T, __y));
-}
-
-
-inline unsigned short
-__rw_atomic_exchange (unsigned short &__x, unsigned short __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (2 == sizeof (unsigned short));
-
-    return __rw_atomic_xchg16 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT16_T*, &__x),
-                               _RWSTD_STATIC_CAST (_RWSTD_INT16_T, __y));
-}
-
-
-inline int
-__rw_atomic_exchange (int &__x, int __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (int));
-
-#ifdef _MSC_VER
-    return _InterlockedExchange (_RWSTD_REINTERPRET_CAST (long*, &__x),
-                                 _RWSTD_STATIC_CAST (long, __y));
-#else
-    return __rw_atomic_xchg32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
-                               _RWSTD_STATIC_CAST (_RWSTD_INT32_T, __y));
-#endif
-}
-
-
-inline unsigned int
-__rw_atomic_exchange (unsigned int &__x, unsigned int __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (4 == sizeof (unsigned int));
-
-#ifdef _MSC_VER
-    return _InterlockedExchange (_RWSTD_REINTERPRET_CAST (long*, &__x),
-                                 _RWSTD_STATIC_CAST (long, __y));
-#else
-    return __rw_atomic_xchg32 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT32_T*, &__x),
-                               _RWSTD_STATIC_CAST (_RWSTD_INT32_T, __y));
-#endif
-}
-
-
-#  if 4 < _RWSTD_LONG_SIZE
-
-inline long
-__rw_atomic_exchange (long &__x, long __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (long));
-
-    return __rw_atomic_xchg64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
-                               _RWSTD_STATIC_CAST (_RWSTD_INT64_T, __y));
-}
-
-
-inline unsigned long
-__rw_atomic_exchange (unsigned long &__x, unsigned long __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned long));
-
-    return __rw_atomic_xchg64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
-                               _RWSTD_STATIC_CAST (_RWSTD_INT64_T, __y));
-}
-
-#  endif   // _RWSTD_LONG_SIZE == _RWSTD_INT_SIZE
-
-
-#ifdef _RWSTD_LONG_LONG
-#  if _RWSTD_LLONG_SIZE > _RWSTD_LONG_SIZE
-
-inline _RWSTD_LONG_LONG
-__rw_atomic_exchange (_RWSTD_LONG_LONG &__x, _RWSTD_LONG_LONG __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (_RWSTD_LONG_LONG));
-
-#ifdef _MSC_VER
-    return _InterlockedExchange64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x),
-                                   _RWSTD_STATIC_CAST (__int64, __y));
-#else
-    return __rw_atomic_xchg64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
-                               _RWSTD_STATIC_CAST (_RWSTD_INT64_T, __y));
-#endif
-}
-
-
-inline unsigned _RWSTD_LONG_LONG
-__rw_atomic_exchange (unsigned _RWSTD_LONG_LONG &__x,
-                      unsigned _RWSTD_LONG_LONG __y, bool)
-{
-    _RWSTD_COMPILE_ASSERT (8 == sizeof (unsigned _RWSTD_LONG_LONG));
-
-#ifdef _MSC_VER
-    return _InterlockedExchange64 (_RWSTD_REINTERPRET_CAST (__int64*, &__x),
-                                   _RWSTD_STATIC_CAST (__int64, __y));
-#else
-    return __rw_atomic_xchg64 (_RWSTD_REINTERPRET_CAST (_RWSTD_INT64_T*, &__x),
-                               _RWSTD_STATIC_CAST (_RWSTD_INT64_T, __y));
-#endif
-}
-
-#  endif   // _RWSTD_LLONG_SIZE > _RWSTD_LONG_SIZE
-#endif   // _RWSTD_LONG_LONG
-
-
-#elif !defined (_RWSTD_NO_ATOMIC_OPS)
-#  define _RWSTD_NO_ATOMIC_OPS
-#endif   // _RWSTD_NO_ATOMIC_OPS
-
-
-/********************** generic bool functions ************************/
-
-#ifndef _RWSTD_NO_BOOL
-
-#  if _RWSTD_BOOL_SIZE == _RWSTD_CHAR_SIZE
-#    define _RWSTD_BOOL_TYPE char
-#  elif _RWSTD_BOOL_SIZE == _RWSTD_SHORT_SIZE
-#    define _RWSTD_BOOL_TYPE short
-#  elif _RWSTD_BOOL_SIZE == _RWSTD_INT_SIZE
-#    define _RWSTD_BOOL_TYPE int
-#  endif
-
-#  ifdef _RWSTD_BOOL_TYPE
-
-inline bool
-__rw_atomic_exchange (bool &__x, bool __y, bool)
-{
-    return 0 != __rw_atomic_exchange (
-                    _RWSTD_REINTERPRET_CAST (_RWSTD_BOOL_TYPE&, __x),
-                    _RWSTD_STATIC_CAST (_RWSTD_BOOL_TYPE, __y),
-                    false);
-}
-
-#    undef _RWSTD_BOOL_TYPE
-#  endif   // _RWSTD_BOOL_TYPE
-
-#endif   // _RWSTD_NO_BOOL
-
-
-/********************** generic long functions ************************/
-
-#if _RWSTD_LONG_SIZE == _RWSTD_INT_SIZE
-
-#  if 6 == _RWSTD_HP_aCC_MAJOR
-     // suppress HP aCC 64 bit migration remark: conversion from
-     // "long *" to "int *" may cause target of pointers to have
-     // a different size
-#    pragma diag_suppress 4230
-#  endif   // HP aCC 6
-
-
-inline long
-__rw_atomic_preincrement (long &__x, bool)
-{
-    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (int&, __x),
-                                     false);
-}
-
-inline unsigned long
-__rw_atomic_preincrement (unsigned long &__x, bool)
-{
-    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (int&, __x),
-                                     false);
-}
-
-inline long
-__rw_atomic_predecrement (long &__x, bool)
-{
-    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (int&, __x),
-                                     false);
-}
-
-inline unsigned long
-__rw_atomic_predecrement (unsigned long &__x, bool)
-{
-    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (int&, __x),
-                                     false);
-}
-
-inline long
-__rw_atomic_exchange (long &__x, long __y, bool)
-{
-    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (int&, __x),
-                                 _RWSTD_STATIC_CAST (int, __y),
-                                 false);
-}
-
-inline unsigned long
-__rw_atomic_exchange (unsigned long &__x,
-                      unsigned long __y, bool)
-{
-    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (int&, __x),
-                                 _RWSTD_STATIC_CAST (int, __y),
-                                 false);
-}
-
-
-#  if 6 == _RWSTD_HP_aCC_MAJOR
-#    pragma diag_default 4230
-#  endif   // HP aCC 6
-
-#endif   // _RWSTD_LONG_SIZE == _RWSTD_INT_SIZE
-
-/********************** generic long long functions *******************/
-
-#ifdef _RWSTD_LONG_LONG
-#  if _RWSTD_LLONG_SIZE == _RWSTD_LONG_SIZE
-
-inline _RWSTD_LONG_LONG
-__rw_atomic_preincrement (_RWSTD_LONG_LONG &__x, bool)
-{
-    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (long&, __x),
-                                     false);
-}
-
-inline unsigned _RWSTD_LONG_LONG
-__rw_atomic_preincrement (unsigned _RWSTD_LONG_LONG &__x, bool)
-{
-    return __rw_atomic_preincrement (_RWSTD_REINTERPRET_CAST (long&, __x),
-                                     false);
-}
-
-inline _RWSTD_LONG_LONG
-__rw_atomic_predecrement (_RWSTD_LONG_LONG &__x, bool)
-{
-    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (long&, __x),
-                                     false);
-}
-
-inline unsigned _RWSTD_LONG_LONG
-__rw_atomic_predecrement (unsigned _RWSTD_LONG_LONG &__x, bool)
-{
-    return __rw_atomic_predecrement (_RWSTD_REINTERPRET_CAST (long&, __x),
-                                     false);
-}
-
-inline _RWSTD_LONG_LONG
-__rw_atomic_exchange (_RWSTD_LONG_LONG &__x, _RWSTD_LONG_LONG __y, bool)
-{
-    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (long&, __x),
-                                 _RWSTD_STATIC_CAST (long, __y),
-                                 false);
-}
-
-inline unsigned _RWSTD_LONG_LONG
-__rw_atomic_exchange (unsigned _RWSTD_LONG_LONG &__x,
-                      unsigned _RWSTD_LONG_LONG __y, bool)
-{
-    return __rw_atomic_exchange (_RWSTD_REINTERPRET_CAST (long&, __x),
-                                 _RWSTD_STATIC_CAST (long, __y),
-                                 false);
-}
-
-#  endif   // _RWSTD_LLONG_SIZE == _RWSTD_LONG_SIZE
-#endif   // _RWSTD_LONG_LONG
-
-
-}   // namespace __rw
+// include atomic functions using mutex object
+#  ifndef _RWSTD_RW_ATOMIC_MUTEX_H_INCLUDED
+#    include <rw/_atomic-mutex.h>
+#  endif   // _RWSTD_RW_ATOMIC_MUTEX_H_INCLUDED
 
 
 #else   // if !defined (_RWSTD_REENTRANT)
 
-
 _RWSTD_NAMESPACE (__rw) { 
 
-// atomic in a single-threaded environment
-template <class _TypeT, class _TypeU>
-inline
-_TypeT __rw_atomic_exchange (_TypeT &__t, const _TypeU &__u, bool)
-{
-    _TypeT __tmp = __t;
-    __t = _TypeT (__u);
-    return __tmp;
-}
-
-
 // dummy classes used as a base class in single-threaded environments
 
 struct __rw_mutex_base
@@ -2173,21 +445,25 @@
 
 #endif   // _RWSTD_REENTRANT
 
+// clean up
+#ifdef _RWSTD_NO_CHAR_ATOMIC_OPS
+#  undef _RWSTD_NO_CHAR_ATOMIC_OPS
+#endif
 
-_RWSTD_NAMESPACE (__rw) { 
+#ifdef _RWSTD_NO_SHORT_ATOMIC_OPS
+#  undef _RWSTD_NO_SHORT_ATOMIC_OPS
+#endif
 
-// available in all environments (ST and MT), used along with
-// __rw_atomic_exchange<>() from conditional expressions in iostreams
-template <class _TypeT, class _TypeU>
-inline
-_TypeT __rw_ordinary_exchange (_TypeT &__t, const _TypeU &__u)
-{
-    _TypeT __tmp = __t;
-    __t = __u;
-    return __tmp;
-}
+#ifdef _RWSTD_NO_INT_ATOMIC_OPS
+#  undef _RWSTD_NO_INT_ATOMIC_OPS
+#endif
 
-}   // namespace __rw
+#ifdef _RWSTD_NO_LONG_ATOMIC_OPS
+#  undef _RWSTD_NO_LONG_ATOMIC_OPS
+#endif
 
+#ifdef _RWSTD_NO_LLONG_ATOMIC_OPS
+#  undef _RWSTD_NO_LLONG_ATOMIC_OPS
+#endif
 
 #endif   // _RWSTD_RW_MUTEX_H_INCLUDED
diff --git a/src/atomic.asm b/src/atomic.asm
index 95efcac..8a3cac2 100644
--- a/src/atomic.asm
+++ b/src/atomic.asm
@@ -28,9 +28,9 @@
 
 
 ifdef Win32
-  include <i86/atomic.inc>
+  include <x86/atomic.inc>
 elseifdef x64
-  include <i86_64/atomic.inc>
+  include <x86_64/atomic.inc>
 endif
 
 end
diff --git a/src/atomic.s b/src/atomic.s
index c7b516e..c748516 100644
--- a/src/atomic.s
+++ b/src/atomic.s
@@ -28,9 +28,9 @@
 
 
 #if defined (__i386__)
-#  include "i86/atomic.s"
+#  include "x86/atomic.s"
 #elif defined (__x86_64) || defined (__x86_64__)
-#  include "i86_64/atomic.s"
+#  include "x86_64/atomic.s"
 #elif defined (__ia64) || defined (__ia64__)
 #  if defined (_LP64) || defined (__LP64__)
 #    include "ia64/atomic-64.s"
diff --git a/src/random.cpp b/src/random.cpp
index adf743d..dcbaaed 100644
--- a/src/random.cpp
+++ b/src/random.cpp
@@ -47,6 +47,8 @@
 #  include <rw/_mutex.h>
 #endif   // _RWSTD_REENTRANT
 
+#include <stddef.h>   // for size_t
+
 
 _RWSTD_NAMESPACE (__rw) {
 
diff --git a/src/i86/atomic.inc b/src/x86/atomic.inc
similarity index 99%
rename from src/i86/atomic.inc
rename to src/x86/atomic.inc
index 2f1682a..bb9ab38 100644
--- a/src/i86/atomic.inc
+++ b/src/x86/atomic.inc
@@ -1,6 +1,6 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;
-; i86/atomic.inc
+; x86/atomic.inc
 ;
 ; $Id$
 ;
diff --git a/src/i86/atomic.s b/src/x86/atomic.s
similarity index 99%
rename from src/i86/atomic.s
rename to src/x86/atomic.s
index 2b0ab02..3f5239d 100644
--- a/src/i86/atomic.s
+++ b/src/x86/atomic.s
@@ -1,6 +1,6 @@
 /***************************************************************************
  *
- * i86/atomic.s
+ * x86/atomic.s
  *
  * $Id$
  *
diff --git a/src/i86_64/atomic.inc b/src/x86_64/atomic.inc
similarity index 99%
rename from src/i86_64/atomic.inc
rename to src/x86_64/atomic.inc
index 5cc5ff3..ef0d8bd 100644
--- a/src/i86_64/atomic.inc
+++ b/src/x86_64/atomic.inc
@@ -1,6 +1,6 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;
-; i86_64/atomic.inc
+; x86_64/atomic.inc
 ;
 ; $Id$
 ;
diff --git a/src/i86_64/atomic.s b/src/x86_64/atomic.s
similarity index 99%
rename from src/i86_64/atomic.s
rename to src/x86_64/atomic.s
index e0f37c2..616af9b 100644
--- a/src/i86_64/atomic.s
+++ b/src/x86_64/atomic.s
@@ -1,6 +1,6 @@
 /***************************************************************************
  *
- * i86_64/atomic.s
+ * x86_64/atomic.s
  *
  * $Id$
  *
diff --git a/tests/containers/23.list.erase.cpp b/tests/containers/23.list.erase.cpp
index 0a378ca..8431470 100644
--- a/tests/containers/23.list.erase.cpp
+++ b/tests/containers/23.list.erase.cpp
@@ -386,7 +386,7 @@
 
                  // assert precondition to silence a bogus HP cadvise
                  // warning #20200-D: Potential null pointer dereference
-                 const ListIter::pointer pres_iter = &*res_iter;
+                 const T* pres_iter = &*res_iter;
                  RW_ASSERT (pres_iter != 0);
 
                  bool success =
diff --git a/tests/include/rw_containers.h b/tests/include/rw_containers.h
index 16a6aa3..e94a02e 100644
--- a/tests/include/rw_containers.h
+++ b/tests/include/rw_containers.h
@@ -2,7 +2,7 @@
 *
 * 23.containers.h - definitions of helpers used in clause 23 tests
 *
-* $Id: 23.containers.h$
+* $Id$
 *
 ***************************************************************************
 *
diff --git a/tests/include/rw_lists.h b/tests/include/rw_lists.h
index 8729105..14a8b90 100644
--- a/tests/include/rw_lists.h
+++ b/tests/include/rw_lists.h
@@ -2,7 +2,7 @@
 *
 * 23.list.h - definitions of helpers used in clause 23.list tests
 *
-* $Id: 23.list.h
+* $Id$
 *
 ***************************************************************************
 *
diff --git a/tests/src/23.containers.cpp b/tests/src/23.containers.cpp
index d93c782..72d5151 100644
--- a/tests/src/23.containers.cpp
+++ b/tests/src/23.containers.cpp
@@ -2,7 +2,7 @@
 *
 * 23.containers.cpp - definitions of helpers used in clause 23 tests
 *
-* $Id: 23.containers.cpp
+* $Id$
 *
 ***************************************************************************
 *
diff --git a/util/ctype.cpp b/util/ctype.cpp
index 5885c0e..41e6cc8 100644
--- a/util/ctype.cpp
+++ b/util/ctype.cpp
@@ -690,7 +690,7 @@
             if (next.token != Scanner::tok_string)
                 issue_diag (E_SYNTAX, true, &next,
                             "expected string following \"copy\" directive\n"); 
-#ifndef _WIN32
+#if !defined (_WIN32) && !defined (__CYGWIN__)
 
             ctype_symlink_ = true;
 
@@ -712,7 +712,7 @@
                 continue;
             }
 
-#endif  // _WIN32
+#endif  // !_WIN32 && !__CYGWIN__
 
             // bump up the nesting level
             nesting_level++;
@@ -891,7 +891,7 @@
     
     }
 
-#ifndef _WIN32
+#if !defined (_WIN32) && !defined (__CYGWIN__)
     
     if (ctype_symlink_) {
 
@@ -909,6 +909,6 @@
         return;
     }
 
-#endif  // _WIN32
+#endif  // !_WIN32 && !__CYGWIN__
 
 }
diff --git a/util/localedef.cpp b/util/localedef.cpp
index 8066b18..25635ea 100644
--- a/util/localedef.cpp
+++ b/util/localedef.cpp
@@ -267,7 +267,7 @@
     if (C_locales.empty ())
         return;
 
-#if !defined (_WIN32)
+#if !defined (_WIN32) && !defined (__CYGWIN__)
 
     if (link_aliases == false)
         return;
@@ -283,7 +283,7 @@
         // pointing to our locale database
         create_symlink (outdir, std_locale, *it);
     }
-#endif  // _WIN32
+#endif  // !_WIN32 && !__CYGWIN__
 }
 
 
diff --git a/util/path.cpp b/util/path.cpp
index 7640591..099c603 100644
--- a/util/path.cpp
+++ b/util/path.cpp
@@ -69,7 +69,7 @@
 }
 
 
-#ifndef _WIN32
+#if !defined (_WIN32) && !defined (__CYGWIN__)
 
 void
 create_symlink (const std::string &dir, 
@@ -112,7 +112,7 @@
     }
 }
 
-#endif  // _WIN32
+#endif  // !_WIN32 && !__CYGWIN__
 
 
 inline int