stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Farid Zaripov" <Farid_Zari...@epam.com>
Subject Patch for MinGW
Date Tue, 10 Jun 2008 16:16:59 GMT
  I've been working on building stdcxx on MinGW.

  Below is patch for review. An option is hardcode
_RWSTD_CRITICAL_SECTION=_CRITICAL_SECTION and 
_RWSTD_INTERLOCKED_T=long for MinGW
(_RWSTD_CRITICAL_SECTION=_RTL_CRITICAL_SECTION and 
_RWSTD_INTERLOCKED_T=volatile long for MSVC respectively) and don't
recover ATOMIC_OPS.cpp config test.
Suggestions?

  ChangeLog:
  * etc/config/src/ATOMIC_OPS.cpp: Restored config test file, deleted in
rev. 614212.
  Determine type of parameter for InterlockedXXX() function on 32-bit
Windows only.
  Determine type of parameter for EnterCriticalSection() and so on
functions.
  * include/rw/_mutex.h: Replaced _RTL_CRITICAL_SECTION to
  _RWSTD_CRITICAL_SECTION, determined at configure step.
  [!_MSC_VER] Added declarations of Win32 API InterlockedXXX()
functions.
  [!_MSC_VER] Added inline _InterlockedXXX() functions for consistency
with MSVC's intinsics.
  Use __try/__except on MSVC (and ICC/Windows) only.


------------------------------------------------------------
Index: etc/config/src/ATOMIC_OPS.cpp
===================================================================
--- etc/config/src/ATOMIC_OPS.cpp	(revision 665767)
+++ etc/config/src/ATOMIC_OPS.cpp	(working copy)
@@ -22,7 +22,7 @@
  * 
 
************************************************************************
**/
 
-#if defined (_WIN32) && !defined (_WIN64)
+#ifdef _WIN32
 
 #include <stdio.h>
 #include <windows.h>
@@ -30,36 +30,45 @@
 
 extern "C" {
 
-typedef int  __stdcall pfiipv_t (int*);
-typedef int  __stdcall pfiip_t (volatile int*);
 typedef long __stdcall pfllp_t (long*);
 typedef long __stdcall pfllpv_t (volatile long*);
 
+struct _CRITICAL_SECTION;
+struct _RTL_CRITICAL_SECTION;
+
+typedef void __stdcall pfvcsp_t (_CRITICAL_SECTION*);
+typedef void __stdcall pfvrcsp_t (_RTL_CRITICAL_SECTION*);
+
 }   // extern "C"
 
 
-const char* foo (pfiip_t) { return "int"; }
-const char* foo (pfiipv_t) { return "volatile int"; }
-
 const char* foo (pfllp_t) { return "long"; }
 const char* foo (pfllpv_t) { return "volatile long"; }
 
+const char* bar (pfvcsp_t) { return "_CRITICAL_SECTION"; }
+const char* bar (pfvrcsp_t) { return "_RTL_CRITICAL_SECTION"; }
 
+
 int main ()
 {
+#  ifndef _WIN64
     // determine the argument type of InterlockedIncrement()
     // (the type changes from long* to volatile long* depending
-    // on the version/patch of MSVC)
-
+    // on the version/patch of PlatformSDK headers)
     printf ("#define _RWSTD_INTERLOCKED_T %s\n", foo
(InterlockedIncrement));
+#  endif   // _WIN64
 
+    // determine the argument type of EnterCriticalSection()
+    // (the type changes from struct _CRITICAL_SECTION to
+    // struct _RTL_CRITICAL_SECTION depending on the version/patch of
+    // PlatformSDK headers)
+    printf ("#define _RWSTD_CRITICAL_SECTION %s\n", bar
(EnterCriticalSection));
+
     return 0;
 }
 
 #else   // not 32-bit Windows
 
-#include <stdio.h>
-
 int main ()
 {
    return 0;
Index: include/rw/_mutex.h
===================================================================
--- include/rw/_mutex.h	(revision 665767)
+++ include/rw/_mutex.h	(working copy)
@@ -125,7 +125,7 @@
 #  ifdef _RWSTD_NO_FWD_DECLARATIONS
 
 #    include <windows.h>
-#    define _RWSTD_MUTEX_T _RTL_CRITICAL_SECTION
+#    define _RWSTD_MUTEX_T _RWSTD_CRITICAL_SECTION
 
 #  else   // if defined (_RWSTD_NO_FWD_DECLARATIONS)
 
@@ -135,20 +135,33 @@
 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"
 
 _RWSTD_NAMESPACE (__rw) { 
@@ -199,15 +212,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);
@@ -218,7 +256,7 @@
     return 0;
 }
 
-inline int __rw_mutex_destroy (_RTL_CRITICAL_SECTION *__mutex)
+inline int __rw_mutex_destroy (_RWSTD_CRITICAL_SECTION *__mutex)
 {
     __try {
         DeleteCriticalSection (__mutex);
@@ -229,7 +267,7 @@
     return 0;
 }
 
-inline int __rw_mutex_lock (_RTL_CRITICAL_SECTION *__mutex)
+inline int __rw_mutex_lock (_RWSTD_CRITICAL_SECTION *__mutex)
 {
     __try {
         EnterCriticalSection (__mutex);
@@ -240,7 +278,7 @@
     return 0;
 }
 
-inline int __rw_mutex_unlock (_RTL_CRITICAL_SECTION *__mutex)
+inline int __rw_mutex_unlock (_RWSTD_CRITICAL_SECTION *__mutex)
 {
     __try {
         LeaveCriticalSection (__mutex);
@@ -252,14 +290,19 @@
 }
 
 #  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
 
 #elif defined (__OS2__)
------------------------------------------------------------

Farid.

Mime
View raw message