summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Windows/Threading.inc
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Support/Windows/Threading.inc')
-rw-r--r--llvm/lib/Support/Windows/Threading.inc41
1 files changed, 20 insertions, 21 deletions
diff --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc
index 12d8cbc21cbc..6448bb478d0c 100644
--- a/llvm/lib/Support/Windows/Threading.inc
+++ b/llvm/lib/Support/Windows/Threading.inc
@@ -23,10 +23,22 @@
#undef MemoryFence
#endif
-HANDLE
-llvm::llvm_execute_on_thread_impl(unsigned(__stdcall *ThreadFunc)(void *),
- void *Arg,
- llvm::Optional<unsigned> StackSizeInBytes) {
+static unsigned __stdcall threadFuncSync(void *Arg) {
+ SyncThreadInfo *TI = static_cast<SyncThreadInfo *>(Arg);
+ TI->UserFn(TI->UserData);
+ return 0;
+}
+
+static unsigned __stdcall threadFuncAsync(void *Arg) {
+ std::unique_ptr<AsyncThreadInfo> Info(static_cast<AsyncThreadInfo *>(Arg));
+ (*Info)();
+ return 0;
+}
+
+static void
+llvm_execute_on_thread_impl(unsigned (__stdcall *ThreadFunc)(void *), void *Arg,
+ llvm::Optional<unsigned> StackSizeInBytes,
+ JoiningPolicy JP) {
HANDLE hThread = (HANDLE)::_beginthreadex(
NULL, StackSizeInBytes.getValueOr(0), ThreadFunc, Arg, 0, NULL);
@@ -34,29 +46,16 @@ llvm::llvm_execute_on_thread_impl(unsigned(__stdcall *ThreadFunc)(void *),
ReportLastErrorFatal("_beginthreadex failed");
}
- return hThread;
-}
-
-void llvm::llvm_thread_join_impl(HANDLE hThread) {
- if (::WaitForSingleObject(hThread, INFINITE) == WAIT_FAILED) {
- ReportLastErrorFatal("WaitForSingleObject failed");
+ if (JP == JoiningPolicy::Join) {
+ if (::WaitForSingleObject(hThread, INFINITE) == WAIT_FAILED) {
+ ReportLastErrorFatal("WaitForSingleObject failed");
+ }
}
-}
-
-void llvm::llvm_thread_detach_impl(HANDLE hThread) {
if (::CloseHandle(hThread) == FALSE) {
ReportLastErrorFatal("CloseHandle failed");
}
}
-DWORD llvm::llvm_thread_get_id_impl(HANDLE hThread) {
- return ::GetThreadId(hThread);
-}
-
-DWORD llvm::llvm_thread_get_current_id_impl() {
- return ::GetCurrentThreadId();
-}
-
uint64_t llvm::get_threadid() {
return uint64_t(::GetCurrentThreadId());
}