[llvm-commits] [llvm] r140011 - /llvm/trunk/lib/Support/Threading.cpp
NAKAMURA Takumi
geek4civic at gmail.com
Mon Sep 19 00:41:44 PDT 2011
Author: chapuni
Date: Mon Sep 19 02:41:43 2011
New Revision: 140011
URL: http://llvm.org/viewvc/llvm-project?rev=140011&view=rev
Log:
Add Win32 support to llvm::llvm_execute_on_thread(). Thanks to Aaron Ballman!
Modified:
llvm/trunk/lib/Support/Threading.cpp
Modified: llvm/trunk/lib/Support/Threading.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Threading.cpp?rev=140011&r1=140010&r2=140011&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Threading.cpp (original)
+++ llvm/trunk/lib/Support/Threading.cpp Mon Sep 19 02:41:43 2011
@@ -102,13 +102,44 @@
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;
+};
+
+static unsigned __stdcall ThreadCallback(void *param) {
+ struct ThreadInfo *info = reinterpret_cast<struct ThreadInfo *>(param);
+ info->func(info->param);
-// No non-pthread implementation, currently.
+ 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,
+ ¶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);
+ }
+}
+#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);
}
More information about the llvm-commits
mailing list