From 172adce767c87898b55eca7f47f53cfe98c13638 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Wed, 3 Jun 2020 11:59:37 -0700 Subject: [PATCH] Posix threads (#6865) Summary: Rocksdb is using the c++11 std::threads feature. The issue is that MINGW only supports it when using Posix threads. This change will allow rocksdb::port::WindowsThread to be replaced with std::thread, which in turn will allow Rocksdb to be cross compiled using MINGW. At the same time, we'll have to use GetCurrentProcessId instead of _getpid. Signed-off-by: Lucian Petrut Pull Request resolved: https://github.com/facebook/rocksdb/pull/6865 Reviewed By: cheng-chang Differential Revision: D21864285 Pulled By: ajkr fbshipit-source-id: 0982eed313e7d34d351b1364c1ccc722da473205 --- CMakeLists.txt | 10 +++++++--- port/win/env_win.cc | 3 +-- port/win/port_win.h | 7 +++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 25fbe7987..354f831f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -804,9 +804,13 @@ if(WIN32) port/win/env_win.cc port/win/env_default.cc port/win/port_win.cc - port/win/win_logger.cc - port/win/win_thread.cc) - + port/win/win_logger.cc) + if(NOT MINGW) + # Mingw only supports std::thread when using + # posix threads. + list(APPEND SOURCES + port/win/win_thread.cc) + endif() if(WITH_XPRESS) list(APPEND SOURCES port/win/xpress_win.cc) diff --git a/port/win/env_win.cc b/port/win/env_win.cc index 6e4524097..9c6a0208f 100644 --- a/port/win/env_win.cc +++ b/port/win/env_win.cc @@ -14,7 +14,6 @@ #include #include -#include // _getpid #include // _access #include // _rmdir, _mkdir, _getcwd #include @@ -906,7 +905,7 @@ Status WinEnvIO::GetTestDirectory(std::string* result) { CreateDir(output); output.append("\\testrocksdb-"); - output.append(std::to_string(_getpid())); + output.append(std::to_string(GetCurrentProcessId())); CreateDir(output); diff --git a/port/win/port_win.h b/port/win/port_win.h index 3dbcb825b..a3ffd559c 100644 --- a/port/win/port_win.h +++ b/port/win/port_win.h @@ -18,12 +18,14 @@ #include #include +#include #include #include #include #include #include #include +#include #include @@ -217,9 +219,14 @@ class CondVar { Mutex* mu_; }; + +#ifdef _POSIX_THREADS +using Thread = std::thread; +#else // Wrapper around the platform efficient // or otherwise preferrable implementation using Thread = WindowsThread; +#endif // OnceInit type helps emulate // Posix semantics with initialization