diff options
| author | NAKAMURA Takumi <geek4civic@gmail.com> | 2011-09-19 07:41:43 +0000 | 
|---|---|---|
| committer | NAKAMURA Takumi <geek4civic@gmail.com> | 2011-09-19 07:41:43 +0000 | 
| commit | dbd883b9152c2abbd5ed2230df2bdc4dae0c2964 (patch) | |
| tree | 43fbb0f7adddfb775541755e062f4c94c644dbf5 | |
| parent | 10acf3577f991409c1910977f70e1369fda9f564 (diff) | |
| download | bcm5719-llvm-dbd883b9152c2abbd5ed2230df2bdc4dae0c2964.tar.gz bcm5719-llvm-dbd883b9152c2abbd5ed2230df2bdc4dae0c2964.zip  | |
Add Win32 support to llvm::llvm_execute_on_thread(). Thanks to Aaron Ballman!
llvm-svn: 140011
| -rw-r--r-- | llvm/lib/Support/Threading.cpp | 35 | 
1 files changed, 33 insertions, 2 deletions
diff --git a/llvm/lib/Support/Threading.cpp b/llvm/lib/Support/Threading.cpp index 29579567ac6..bf432a9af71 100644 --- a/llvm/lib/Support/Threading.cpp +++ b/llvm/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, +                                            ¶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);  }  | 

