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 (WAIT_OBJECT_0 != ::WaitForSingleObject(m_thread, INFINITE)) 40 { 41 error.SetError(::GetLastError(), lldb::eErrorTypeWin32); 42 return error; 43 } 44 45 m_state = (m_state == eThreadStateCancelling) ? eThreadStateCancelled : eThreadStateExited; 46 47 if (result) 48 { 49 DWORD dword_result = 0; 50 if (!::GetExitCodeThread(m_thread, &dword_result)) 51 *result = 0; 52 *result = dword_result; 53 } 54 return error; 55 } 56 57 Error 58 HostThreadWindows::Cancel() 59 { 60 Error error; 61 62 DWORD result = ::QueueUserAPC(::ExitThread, m_thread, 0); 63 error.SetError(result, eErrorTypeWin32); 64 return error; 65 } 66 67 lldb::tid_t 68 HostThreadWindows::GetThreadId() const 69 { 70 return ::GetThreadId(m_thread); 71 } 72 73 void 74 HostThreadWindows::Reset() 75 { 76 if (m_thread != LLDB_INVALID_HOST_THREAD) 77 ::CloseHandle(m_thread); 78 79 HostNativeThreadBase::Reset(); 80 } 81