diff options
| author | Sam McCall <sammccall@google.com> | 2019-10-23 15:10:35 +0200 |
|---|---|---|
| committer | Sam McCall <sammccall@google.com> | 2019-10-23 15:10:35 +0200 |
| commit | 7bc7fe6b789d25d48d6dc71d533a411e9e981237 (patch) | |
| tree | 1b61de736858e27c933931953ff3926ad6747c91 /llvm/lib/Support/Windows | |
| parent | 40668abca4d307e02b33345cfdb7271549ff48d0 (diff) | |
| download | bcm5719-llvm-7bc7fe6b789d25d48d6dc71d533a411e9e981237.tar.gz bcm5719-llvm-7bc7fe6b789d25d48d6dc71d533a411e9e981237.zip | |
Revert "[Support] Add a way to run a function on a detached thread"
This reverts commit 40668abca4d307e02b33345cfdb7271549ff48d0.
This causes clang tests to fail, as stacksize=0 is being explicitly passed and
is no longer a no-op.
Diffstat (limited to 'llvm/lib/Support/Windows')
| -rw-r--r-- | llvm/lib/Support/Windows/Process.inc | 7 | ||||
| -rw-r--r-- | llvm/lib/Support/Windows/Threading.inc | 50 | ||||
| -rw-r--r-- | llvm/lib/Support/Windows/WindowsSupport.h | 8 |
3 files changed, 32 insertions, 33 deletions
diff --git a/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc index 3526e3dee6f..4b91f9f7fc6 100644 --- a/llvm/lib/Support/Windows/Process.inc +++ b/llvm/lib/Support/Windows/Process.inc @@ -439,6 +439,13 @@ const char *Process::ResetColor() { return 0; } +// Include GetLastError() in a fatal error message. +static void ReportLastErrorFatal(const char *Msg) { + std::string ErrMsg; + MakeErrMsg(&ErrMsg, Msg); + report_fatal_error(ErrMsg); +} + unsigned Process::GetRandomNumber() { HCRYPTPROV HCPC; if (!::CryptAcquireContextW(&HCPC, NULL, NULL, PROV_RSA_FULL, diff --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc index 83b47ea1e3d..96649472cc9 100644 --- a/llvm/lib/Support/Windows/Threading.inc +++ b/llvm/lib/Support/Windows/Threading.inc @@ -21,36 +21,36 @@ #undef MemoryFence #endif -static unsigned __stdcall threadFuncSync(void *Arg) { - SyncThreadInfo *TI = static_cast<SyncThreadInfo *>(Arg); - TI->UserFn(TI->UserData); - return 0; +namespace { + struct ThreadInfo { + void(*func)(void*); + void *param; + }; } -static unsigned __stdcall threadFuncAsync(void *Arg) { - std::unique_ptr<AsyncThreadInfo> Info(static_cast<AsyncThreadInfo *>(Arg)); - (*Info)(); +static unsigned __stdcall ThreadCallback(void *param) { + struct ThreadInfo *info = reinterpret_cast<struct ThreadInfo *>(param); + info->func(info->param); + return 0; } -static void -llvm_execute_on_thread_impl(_beginthreadex_proc_type ThreadFunc, void *Arg, - llvm::Optional<unsigned> StackSizeInBytes, - JoiningPolicy JP) { - HANDLE hThread = (HANDLE)::_beginthreadex( - NULL, StackSizeInBytes.getValueOr(0), ThreadFunc, Arg, 0, NULL); - - if (!hThread) { - ReportLastErrorFatal("_beginthreadex failed"); - } - - if (JP == JoiningPolicy::Join) { - if (::WaitForSingleObject(hThread, INFINITE) == WAIT_FAILED) { - ReportLastErrorFatal("WaitForSingleObject failed"); - } - } - if (::CloseHandle(hThread) == FALSE) { - ReportLastErrorFatal("CloseHandle failed"); +void llvm::llvm_execute_on_thread(void(*Fn)(void*), void *UserData, + unsigned RequestedStackSize) { + struct ThreadInfo param = { Fn, UserData }; + + HANDLE hThread = (HANDLE)::_beginthreadex(NULL, + RequestedStackSize, ThreadCallback, + ¶m, 0, NULL); + + if (hThread) { + // We actually don't care whether the wait succeeds or fails, in + // the same way we don't care whether the pthread_join call succeeds + // or fails. There's not much we could do if this were to fail. But + // on success, this call will wait until the thread finishes executing + // before returning. + (void)::WaitForSingleObject(hThread, INFINITE); + ::CloseHandle(hThread); } } diff --git a/llvm/lib/Support/Windows/WindowsSupport.h b/llvm/lib/Support/Windows/WindowsSupport.h index bb7e79b8601..2e2e97430b7 100644 --- a/llvm/lib/Support/Windows/WindowsSupport.h +++ b/llvm/lib/Support/Windows/WindowsSupport.h @@ -41,7 +41,6 @@ #include "llvm/Support/Allocator.h" #include "llvm/Support/Chrono.h" #include "llvm/Support/Compiler.h" -#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/VersionTuple.h" #include <cassert> #include <string> @@ -67,13 +66,6 @@ llvm::VersionTuple GetWindowsOSVersion(); bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix); -// Include GetLastError() in a fatal error message. -LLVM_ATTRIBUTE_NORETURN inline void ReportLastErrorFatal(const char *Msg) { - std::string ErrMsg; - MakeErrMsg(&ErrMsg, Msg); - llvm::report_fatal_error(ErrMsg); -} - template <typename HandleTraits> class ScopedHandle { typedef typename HandleTraits::handle_type handle_type; |

