llvm.org GIT mirror llvm / 92ec8e1
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 NAKAMURA Takumi 8 years ago
1 changed file(s) with 34 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
101101 error:
102102 ::pthread_attr_destroy(&Attr);
103103 }
104 #elif defined(LLVM_MULTITHREADED) && defined(LLVM_ON_WIN32)
105 #include "Windows/Windows.h"
106 #include
104107
108 struct ThreadInfo {
109 void (*func)(void*);
110 void *param;
111 };
112
113 static unsigned __stdcall ThreadCallback(void *param) {
114 struct ThreadInfo *info = reinterpret_cast(param);
115 info->func(info->param);
116
117 return 0;
118 }
119
120 void llvm::llvm_execute_on_thread(void (*Fn)(void*), void *UserData,
121 unsigned RequestedStackSize) {
122 struct ThreadInfo param = { Fn, UserData };
123
124 HANDLE hThread = (HANDLE)::_beginthreadex(NULL,
125 RequestedStackSize, ThreadCallback,
126 ¶m, 0, NULL);
127
128 if (hThread) {
129 // We actually don't care whether the wait succeeds or fails, in
130 // the same way we don't care whether the pthread_join call succeeds
131 // or fails. There's not much we could do if this were to fail. But
132 // on success, this call will wait until the thread finishes executing
133 // before returning.
134 (void)::WaitForSingleObject(hThread, INFINITE);
135 ::CloseHandle(hThread);
136 }
137 }
105138 #else
106
107 // No non-pthread implementation, currently.
108
139 // Support for non-Win32, non-pthread implementation.
109140 void llvm::llvm_execute_on_thread(void (*Fn)(void*), void *UserData,
110141 unsigned RequestedStackSize) {
111142 (void) RequestedStackSize;