Allow using WindowsThread with Mingw (#8108)
Summary: Allow using WindowsThread with Mingw Most Mingw builds require Posix threads in order to use std::thread. As per https://github.com/facebook/rocksdb/issues/7764, this is not always the case. That being considered, we're going to improve the Mingw thread model checks. Closes: https://github.com/facebook/rocksdb/issues/7764 Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com> Pull Request resolved: https://github.com/facebook/rocksdb/pull/8108 Reviewed By: jay-zhuang Differential Revision: D27365778 Pulled By: mrambacher fbshipit-source-id: 2c15b1f04ae90e1e3a25a33e86ceb779224a9529
This commit is contained in:
parent
373e3a154d
commit
390c5246d2
@ -934,13 +934,8 @@ 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
|
||||||
if(NOT MINGW)
|
port/win/win_thread.cc)
|
||||||
# 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)
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
#include "port/win/env_win.h"
|
#include "port/win/env_win.h"
|
||||||
#include "port/win/io_win.h"
|
#include "port/win/io_win.h"
|
||||||
#include "port/win/win_logger.h"
|
#include "port/win/win_logger.h"
|
||||||
#include "port/win/win_thread.h"
|
|
||||||
#include "rocksdb/env.h"
|
#include "rocksdb/env.h"
|
||||||
#include "rocksdb/slice.h"
|
#include "rocksdb/slice.h"
|
||||||
#include "strsafe.h"
|
#include "strsafe.h"
|
||||||
@ -1291,7 +1290,7 @@ void WinEnvThreads::StartThread(void (*function)(void* arg), void* arg) {
|
|||||||
state->user_function = function;
|
state->user_function = function;
|
||||||
state->arg = arg;
|
state->arg = arg;
|
||||||
try {
|
try {
|
||||||
ROCKSDB_NAMESPACE::port::WindowsThread th(&StartThreadWrapper, state.get());
|
Thread th(&StartThreadWrapper, state.get());
|
||||||
state.release();
|
state.release();
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lg(mu_);
|
std::lock_guard<std::mutex> lg(mu_);
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "env/composite_env_wrapper.h"
|
#include "env/composite_env_wrapper.h"
|
||||||
#include "port/win/win_thread.h"
|
#include "port/port.h"
|
||||||
#include "rocksdb/env.h"
|
#include "rocksdb/env.h"
|
||||||
#include "rocksdb/file_system.h"
|
#include "rocksdb/file_system.h"
|
||||||
#include "rocksdb/system_clock.h"
|
#include "rocksdb/system_clock.h"
|
||||||
@ -71,7 +71,7 @@ class WinEnvThreads {
|
|||||||
Env* hosted_env_;
|
Env* hosted_env_;
|
||||||
mutable std::mutex mu_;
|
mutable std::mutex mu_;
|
||||||
std::vector<ThreadPoolImpl> thread_pools_;
|
std::vector<ThreadPoolImpl> thread_pools_;
|
||||||
std::vector<WindowsThread> threads_to_join_;
|
std::vector<Thread> threads_to_join_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WinClock : public SystemClock {
|
class WinClock : public SystemClock {
|
||||||
|
@ -8,6 +8,11 @@
|
|||||||
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
// Most Mingw builds support std::thread only when using posix threads.
|
||||||
|
// In that case, some of these functions will be unavailable.
|
||||||
|
// Note that we're using either WindowsThread or std::thread, depending on
|
||||||
|
// which one is available.
|
||||||
|
#ifndef _POSIX_THREADS
|
||||||
|
|
||||||
#include "port/win/win_thread.h"
|
#include "port/win/win_thread.h"
|
||||||
|
|
||||||
@ -180,4 +185,5 @@ unsigned int __stdcall WindowsThread::Data::ThreadProc(void* arg) {
|
|||||||
} // namespace port
|
} // namespace port
|
||||||
} // namespace ROCKSDB_NAMESPACE
|
} // namespace ROCKSDB_NAMESPACE
|
||||||
|
|
||||||
#endif
|
#endif // OS_WIN
|
||||||
|
#endif // !_POSIX_THREADS
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef _POSIX_THREADS
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@ -120,3 +122,4 @@ inline void swap(ROCKSDB_NAMESPACE::port::WindowsThread& th1,
|
|||||||
}
|
}
|
||||||
} // namespace std
|
} // namespace std
|
||||||
|
|
||||||
|
#endif // !_POSIX_THREADS
|
||||||
|
Loading…
Reference in New Issue
Block a user