aboutsummaryrefslogtreecommitdiff
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.inc43
1 files changed, 23 insertions, 20 deletions
diff --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc
index 6448bb478d0c..7b48ca8fb1fb 100644
--- a/llvm/lib/Support/Windows/Threading.inc
+++ b/llvm/lib/Support/Windows/Threading.inc
@@ -23,22 +23,10 @@
#undef MemoryFence
#endif
-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) {
+namespace llvm {
+HANDLE
+llvm_execute_on_thread_impl(unsigned(__stdcall *ThreadFunc)(void *), void *Arg,
+ llvm::Optional<unsigned> StackSizeInBytes) {
HANDLE hThread = (HANDLE)::_beginthreadex(
NULL, StackSizeInBytes.getValueOr(0), ThreadFunc, Arg, 0, NULL);
@@ -46,16 +34,31 @@ llvm_execute_on_thread_impl(unsigned (__stdcall *ThreadFunc)(void *), void *Arg,
ReportLastErrorFatal("_beginthreadex failed");
}
- if (JP == JoiningPolicy::Join) {
- if (::WaitForSingleObject(hThread, INFINITE) == WAIT_FAILED) {
- ReportLastErrorFatal("WaitForSingleObject failed");
- }
+ return hThread;
+}
+
+void llvm_thread_join_impl(HANDLE hThread) {
+ if (::WaitForSingleObject(hThread, INFINITE) == WAIT_FAILED) {
+ ReportLastErrorFatal("WaitForSingleObject failed");
}
+}
+
+void llvm_thread_detach_impl(HANDLE hThread) {
if (::CloseHandle(hThread) == FALSE) {
ReportLastErrorFatal("CloseHandle failed");
}
}
+DWORD llvm_thread_get_id_impl(HANDLE hThread) {
+ return ::GetThreadId(hThread);
+}
+
+DWORD llvm_thread_get_current_id_impl() {
+ return ::GetCurrentThreadId();
+}
+
+} // namespace llvm
+
uint64_t llvm::get_threadid() {
return uint64_t(::GetCurrentThreadId());
}