1 //===-- HostThreadWindows.cpp -----------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Core/Error.h" 11 12 #include "lldb/Host/windows/windows.h" 13 #include "lldb/Host/windows/HostThreadWindows.h" 14 15 #include "llvm/ADT/STLExtras.h" 16 17 using namespace lldb; 18 using namespace lldb_private; 19 20 HostThreadWindows::HostThreadWindows() 21 : HostNativeThreadBase() 22 { 23 } 24 25 HostThreadWindows::HostThreadWindows(lldb::thread_t thread) 26 : HostNativeThreadBase(thread) 27 { 28 } 29 30 HostThreadWindows::~HostThreadWindows() 31 { 32 Reset(); 33 } 34 35 Error 36 HostThreadWindows::Join(lldb::thread_result_t *result) 37 { 38 Error error; 39 if (IsJoinable()) 40 { 41 DWORD wait_result = ::WaitForSingleObject(m_thread, INFINITE); 42 if (WAIT_OBJECT_0 == wait_result && result) 43 { 44 DWORD exit_code = 0; 45 if (!::GetExitCodeThread(m_thread, &exit_code)) 46 *result = 0; 47 *result = exit_code; 48 } 49 else if (WAIT_OBJECT_0 != wait_result) 50 error.SetError(::GetLastError(), eErrorTypeWin32); 51 } 52 else 53 error.SetError(ERROR_INVALID_HANDLE, eErrorTypeWin32); 54 55 Reset (); 56 return error; 57 } 58 59 Error 60 HostThreadWindows::Cancel() 61 { 62 Error error; 63 64 DWORD result = ::QueueUserAPC(::ExitThread, m_thread, 0); 65 error.SetError(result, eErrorTypeWin32); 66 return error; 67 } 68 69 lldb::tid_t 70 HostThreadWindows::GetThreadId() const 71 { 72 return ::GetThreadId(m_thread); 73 } 74 75 void 76 HostThreadWindows::Reset() 77 { 78 if (m_thread != LLDB_INVALID_HOST_THREAD) 79 ::CloseHandle(m_thread); 80 81 HostNativeThreadBase::Reset(); 82 } 83