You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by fa...@apache.org on 2008/07/01 18:06:00 UTC

svn commit: r673122 - in /stdcxx/branches/4.2.x: etc/config/src/ATOMIC_OPS.cpp include/rw/_mutex.h

Author: faridz
Date: Tue Jul  1 09:06:00 2008
New Revision: 673122

URL: http://svn.apache.org/viewvc?rev=673122&view=rev
Log:
2008-07-01  Farid Zaripov  <fa...@apache.com>

	* etc/config/src/ATOMIC_OPS.cpp: Restored config test file, deleted
	in rev. 614212.
	* include/rw/_mutex.h: Define new macro _RWSTD_CRITICAL_SECTION
	defined as _CRITICAL_SECTION on gcc/MinGW and _RTL_CRITICAL_SECTION 
	on other Windows compilers.
	[_RWSTD_INTERLOCKED_T && !_MSC_VER] Added declarations of Win32 API
	InterlockedXXX() functions. Added definitions of the inline
	_InterlockedXXX() functions for consistency with MSVC's intinsics.
	Use __try/__except on MSVC (and ICC/Windows) only.

Added:
    stdcxx/branches/4.2.x/etc/config/src/ATOMIC_OPS.cpp
      - copied unchanged from r614211, stdcxx/branches/4.2.x/etc/config/src/ATOMIC_OPS.cpp
Modified:
    stdcxx/branches/4.2.x/include/rw/_mutex.h

Modified: stdcxx/branches/4.2.x/include/rw/_mutex.h
URL: http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/include/rw/_mutex.h?rev=673122&r1=673121&r2=673122&view=diff
==============================================================================
--- stdcxx/branches/4.2.x/include/rw/_mutex.h (original)
+++ stdcxx/branches/4.2.x/include/rw/_mutex.h Tue Jul  1 09:06:00 2008
@@ -122,13 +122,19 @@
 
 #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 _RTL_CRITICAL_SECTION
+#    define _RWSTD_MUTEX_T _RWSTD_CRITICAL_SECTION
 
 #  else   // if !defined (_RWSTD_NO_FWD_DECLARATIONS)
 
@@ -138,19 +144,32 @@
 extern "C" {
 
 // but rather declare these globals here
-struct _RTL_CRITICAL_SECTION;
+struct _RWSTD_CRITICAL_SECTION;
 
 __declspec (dllimport) void __stdcall
-InitializeCriticalSection (_RTL_CRITICAL_SECTION*);
+InitializeCriticalSection (_RWSTD_CRITICAL_SECTION*);
 
 __declspec (dllimport) void __stdcall
-EnterCriticalSection (_RTL_CRITICAL_SECTION*);
+EnterCriticalSection (_RWSTD_CRITICAL_SECTION*);
 
 __declspec (dllimport) void __stdcall
-LeaveCriticalSection (_RTL_CRITICAL_SECTION*);
+LeaveCriticalSection (_RWSTD_CRITICAL_SECTION*);
 
 __declspec (dllimport) void __stdcall
-DeleteCriticalSection (_RTL_CRITICAL_SECTION*);
+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"
 
@@ -202,15 +221,40 @@
 #        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 (_RTL_CRITICAL_SECTION *__mutex)
+inline int __rw_mutex_init (_RWSTD_CRITICAL_SECTION *__mutex)
 {
     __try {
         InitializeCriticalSection (__mutex);
@@ -221,7 +265,7 @@
     return 0;
 }
 
-inline int __rw_mutex_destroy (_RTL_CRITICAL_SECTION *__mutex)
+inline int __rw_mutex_destroy (_RWSTD_CRITICAL_SECTION *__mutex)
 {
     __try {
         DeleteCriticalSection (__mutex);
@@ -232,7 +276,7 @@
     return 0;
 }
 
-inline int __rw_mutex_lock (_RTL_CRITICAL_SECTION *__mutex)
+inline int __rw_mutex_lock (_RWSTD_CRITICAL_SECTION *__mutex)
 {
     __try {
         EnterCriticalSection (__mutex);
@@ -243,7 +287,7 @@
     return 0;
 }
 
-inline int __rw_mutex_unlock (_RTL_CRITICAL_SECTION *__mutex)
+inline int __rw_mutex_unlock (_RWSTD_CRITICAL_SECTION *__mutex)
 {
     __try {
         LeaveCriticalSection (__mutex);
@@ -255,13 +299,18 @@
 }
 
 #  define _RWSTD_MUTEX_INIT(mutex)      \
-   __rw_mutex_init (_RWSTD_REINTERPRET_CAST (_RTL_CRITICAL_SECTION*, &mutex))
+   __rw_mutex_init (_RWSTD_REINTERPRET_CAST (_RWSTD_CRITICAL_SECTION*, &mutex))
 #  define _RWSTD_MUTEX_DESTROY(mutex)   \
-   __rw_mutex_destroy (_RWSTD_REINTERPRET_CAST (_RTL_CRITICAL_SECTION*, &mutex))
+   __rw_mutex_destroy (_RWSTD_REINTERPRET_CAST (_RWSTD_CRITICAL_SECTION*, &mutex))
 #  define _RWSTD_MUTEX_LOCK(mutex)      \
-   __rw_mutex_lock (_RWSTD_REINTERPRET_CAST (_RTL_CRITICAL_SECTION*, &mutex))
+   __rw_mutex_lock (_RWSTD_REINTERPRET_CAST (_RWSTD_CRITICAL_SECTION*, &mutex))
 #  define _RWSTD_MUTEX_UNLOCK(mutex)    \
-   __rw_mutex_unlock (_RWSTD_REINTERPRET_CAST (_RTL_CRITICAL_SECTION*, &mutex))
+   __rw_mutex_unlock (_RWSTD_REINTERPRET_CAST (_RWSTD_CRITICAL_SECTION*, &mutex))
+
+#  ifndef _MSC_VER
+#    undef __try
+#    undef __except
+#  endif   // _MSC_VER
 
 }   // namespace __rw