From 9759dcda3c2f9c174521b9269018f79f55c29df8 Mon Sep 17 00:00:00 2001 From: Daniele Tamino Date: Fri, 19 Feb 2016 19:06:12 -0800 Subject: Fix compilation on MinGW with native threads --- googletest/include/gtest/internal/gtest-port.h | 12 +++++++++--- googletest/test/gtest-port_test.cc | 7 +++++++ googletest/test/gtest_unittest.cc | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 7d6e465..634b9ab 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -396,10 +396,16 @@ # include # endif // In order to avoid having to include , use forward declaration -// assuming CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION. +#if GTEST_OS_WINDOWS_MINGW +// MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two +// separate (equivalent) structs, instead of using typedef +typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION; +#else +// Assume CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION. // This assumption is verified by // WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION. -struct _RTL_CRITICAL_SECTION; +typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; +#endif #else // This assumes that non-Windows OSes provide unistd.h. For OSes where this // is not the case, we need to include headers that provide the functions @@ -1693,7 +1699,7 @@ class GTEST_API_ Mutex { // by the linker. MutexType type_; long critical_section_init_phase_; // NOLINT - _RTL_CRITICAL_SECTION* critical_section_; + GTEST_CRITICAL_SECTION* critical_section_; GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex); }; diff --git a/googletest/test/gtest-port_test.cc b/googletest/test/gtest-port_test.cc index 6ea607b..05f8821 100644 --- a/googletest/test/gtest-port_test.cc +++ b/googletest/test/gtest-port_test.cc @@ -1295,9 +1295,16 @@ TEST(WindowsTypesTest, HANDLEIsVoidStar) { StaticAssertTypeEq(); } +#if GTEST_OS_WINDOWS_MINGW +TEST(WindowsTypesTest, _CRITICAL_SECTIONIs_CRITICAL_SECTION) { + StaticAssertTypeEq(); +} +#else TEST(WindowsTypesTest, CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION) { StaticAssertTypeEq(); } +#endif + #endif // GTEST_OS_WINDOWS } // namespace internal diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 88e9413..97fcd5a 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -442,7 +442,7 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test { // tzset() distinguishes between the TZ variable being present and empty // and not being present, so we have to consider the case of time_zone // being NULL. -#if _MSC_VER +#if _MSC_VER || GTEST_OS_WINDOWS_MINGW // ...Unless it's MSVC, whose standard library's _putenv doesn't // distinguish between an empty and a missing variable. const std::string env_var = -- cgit v0.12 From a138385e48ee755ab8d124d6090c05580c8e9342 Mon Sep 17 00:00:00 2001 From: Daniele Tamino Date: Mon, 22 Feb 2016 13:08:19 -0800 Subject: Don't use pthread when on MinGW even if available It's not supported, and native Windows threading is available for MinGW --- googletest/cmake/internal_utils.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 93e6dbb..814fa56 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -46,7 +46,9 @@ endmacro() # Google Mock. You can tweak these definitions to suit your need. A # variable's value is empty before it's explicitly assigned to. macro(config_compiler_and_linker) - if (NOT gtest_disable_pthreads) + # Note: pthreads on MinGW is not supported, even if available + # instead, we use windows threading primitives + if (NOT gtest_disable_pthreads AND NOT MINGW) # Defines CMAKE_USE_PTHREADS_INIT and CMAKE_THREAD_LIBS_INIT. find_package(Threads) endif() -- cgit v0.12