Skip to content

Commit

Permalink
Posix threads (facebook#6865)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Pull Request resolved: facebook#6865

Reviewed By: cheng-chang

Differential Revision: D21864285

Pulled By: ajkr

fbshipit-source-id: 0982eed313e7d34d351b1364c1ccc722da473205
  • Loading branch information
petrutlucian94 authored and facebook-github-bot committed Jun 3, 2020
1 parent 43f8a9d commit 172adce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions port/win/env_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <thread>

#include <errno.h>
#include <process.h> // _getpid
#include <io.h> // _access
#include <direct.h> // _rmdir, _mkdir, _getcwd
#include <sys/types.h>
Expand Down Expand Up @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions port/win/port_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

#include <windows.h>
#include <string>
#include <thread>
#include <string.h>
#include <mutex>
#include <limits>
#include <condition_variable>
#include <malloc.h>
#include <intrin.h>
#include <process.h>

#include <stdint.h>

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 172adce

Please sign in to comment.