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 <lpetrut@cloudbasesolutions.com>
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6865

Reviewed By: cheng-chang

Differential Revision: D21864285

Pulled By: ajkr

fbshipit-source-id: 0982eed313e7d34d351b1364c1ccc722da473205
This commit is contained in:
Lucian Petrut 2020-06-03 11:59:37 -07:00 committed by Facebook GitHub Bot
parent 43f8a9dcce
commit 172adce767
3 changed files with 15 additions and 5 deletions

View File

@ -804,9 +804,13 @@ if(WIN32)
port/win/env_win.cc port/win/env_win.cc
port/win/env_default.cc port/win/env_default.cc
port/win/port_win.cc port/win/port_win.cc
port/win/win_logger.cc port/win/win_logger.cc)
port/win/win_thread.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) if(WITH_XPRESS)
list(APPEND SOURCES list(APPEND SOURCES
port/win/xpress_win.cc) port/win/xpress_win.cc)

View File

@ -14,7 +14,6 @@
#include <thread> #include <thread>
#include <errno.h> #include <errno.h>
#include <process.h> // _getpid
#include <io.h> // _access #include <io.h> // _access
#include <direct.h> // _rmdir, _mkdir, _getcwd #include <direct.h> // _rmdir, _mkdir, _getcwd
#include <sys/types.h> #include <sys/types.h>
@ -906,7 +905,7 @@ Status WinEnvIO::GetTestDirectory(std::string* result) {
CreateDir(output); CreateDir(output);
output.append("\\testrocksdb-"); output.append("\\testrocksdb-");
output.append(std::to_string(_getpid())); output.append(std::to_string(GetCurrentProcessId()));
CreateDir(output); CreateDir(output);

View File

@ -18,12 +18,14 @@
#include <windows.h> #include <windows.h>
#include <string> #include <string>
#include <thread>
#include <string.h> #include <string.h>
#include <mutex> #include <mutex>
#include <limits> #include <limits>
#include <condition_variable> #include <condition_variable>
#include <malloc.h> #include <malloc.h>
#include <intrin.h> #include <intrin.h>
#include <process.h>
#include <stdint.h> #include <stdint.h>
@ -217,9 +219,14 @@ class CondVar {
Mutex* mu_; Mutex* mu_;
}; };
#ifdef _POSIX_THREADS
using Thread = std::thread;
#else
// Wrapper around the platform efficient // Wrapper around the platform efficient
// or otherwise preferrable implementation // or otherwise preferrable implementation
using Thread = WindowsThread; using Thread = WindowsThread;
#endif
// OnceInit type helps emulate // OnceInit type helps emulate
// Posix semantics with initialization // Posix semantics with initialization