aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2011-09-19 07:41:43 +0000
committerNAKAMURA Takumi <geek4civic@gmail.com>2011-09-19 07:41:43 +0000
commit92ec8e1427e595d540f2238c7a1bb05fbd013013 (patch)
treefe4d9f436f2ff5226bd6b75414c021bfc7443bd1 /lib
parent0a3eb6095252ca4e12006e540917c93864bd582b (diff)
downloadexternal_llvm-92ec8e1427e595d540f2238c7a1bb05fbd013013.zip
external_llvm-92ec8e1427e595d540f2238c7a1bb05fbd013013.tar.gz
external_llvm-92ec8e1427e595d540f2238c7a1bb05fbd013013.tar.bz2
Add Win32 support to llvm::llvm_execute_on_thread(). Thanks to Aaron Ballman!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@140011 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Support/Threading.cpp35
1 files changed, 33 insertions, 2 deletions
diff --git a/lib/Support/Threading.cpp b/lib/Support/Threading.cpp
index 2957956..bf432a9 100644
--- a/lib/Support/Threading.cpp
+++ b/lib/Support/Threading.cpp
@@ -102,13 +102,44 @@ void llvm::llvm_execute_on_thread(void (*Fn)(void*), void *UserData,
error:
::pthread_attr_destroy(&Attr);
}
+#elif defined(LLVM_MULTITHREADED) && defined(LLVM_ON_WIN32)
+#include "Windows/Windows.h"
+#include <process.h>
-#else
+struct ThreadInfo {
+ void (*func)(void*);
+ void *param;
+};
-// No non-pthread implementation, currently.
+static unsigned __stdcall ThreadCallback(void *param) {
+ struct ThreadInfo *info = reinterpret_cast<struct ThreadInfo *>(param);
+ info->func(info->param);
+
+ return 0;
+}
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,
+ &param, 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);
+ }
+}
+#else
+// Support for non-Win32, non-pthread implementation.
+void llvm::llvm_execute_on_thread(void (*Fn)(void*), void *UserData,
+ unsigned RequestedStackSize) {
(void) RequestedStackSize;
Fn(UserData);
}