diff options
author | Zachary Turner <zturner@google.com> | 2014-09-09 20:54:56 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2014-09-09 20:54:56 +0000 |
commit | 39de3110712cb4547a835777310dbead46c1a002 (patch) | |
tree | d0f99eb4b7f8ab35272587ad4a0e070675752b54 /lldb/source/Host/windows/HostThreadWindows.cpp | |
parent | 7decae153bdb4b4a98fa48bb27564fa4597d1cfa (diff) | |
download | bcm5719-llvm-39de3110712cb4547a835777310dbead46c1a002.tar.gz bcm5719-llvm-39de3110712cb4547a835777310dbead46c1a002.zip |
Create a HostThread abstraction.
This patch moves creates a thread abstraction that represents a
thread running inside the LLDB process. This is a replacement for
otherwise using lldb::thread_t, and provides a platform agnostic
interface to managing these threads.
Differential Revision: http://reviews.llvm.org/D5198
Reviewed by: Jim Ingham
llvm-svn: 217460
Diffstat (limited to 'lldb/source/Host/windows/HostThreadWindows.cpp')
-rw-r--r-- | lldb/source/Host/windows/HostThreadWindows.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/lldb/source/Host/windows/HostThreadWindows.cpp b/lldb/source/Host/windows/HostThreadWindows.cpp new file mode 100644 index 00000000000..5d526cc2530 --- /dev/null +++ b/lldb/source/Host/windows/HostThreadWindows.cpp @@ -0,0 +1,80 @@ +//===-- HostThreadWindows.cpp -----------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Core/Error.h" + +#include "lldb/Host/windows/windows.h" +#include "lldb/Host/windows/HostThreadWindows.h" + +#include "llvm/ADT/STLExtras.h" + +using namespace lldb; +using namespace lldb_private; + +HostThreadWindows::HostThreadWindows() + : HostNativeThreadBase() +{ +} + +HostThreadWindows::HostThreadWindows(lldb::thread_t thread) + : HostNativeThreadBase(thread) +{ +} + +HostThreadWindows::~HostThreadWindows() +{ + Reset(); +} + +Error +HostThreadWindows::Join(lldb::thread_result_t *result) +{ + Error error; + if (WAIT_OBJECT_0 != ::WaitForSingleObject(m_thread, INFINITE)) + { + error.SetError(::GetLastError(), lldb::eErrorTypeWin32); + return error; + } + + m_state = (m_state == eThreadStateCancelling) ? eThreadStateCancelled : eThreadStateExited; + + if (result) + { + DWORD dword_result = 0; + if (!::GetExitCodeThread(m_thread, &dword_result)) + *result = 0; + *result = dword_result; + } + return error; +} + +Error +HostThreadWindows::Cancel() +{ + Error error; + + DWORD result = ::QueueUserAPC(::ExitThread, m_thread, 0); + error.SetError(result, eErrorTypeWin32); + return error; +} + +lldb::tid_t +HostThreadWindows::GetThreadId() const +{ + return ::GetThreadId(m_thread); +} + +void +HostThreadWindows::Reset() +{ + if (m_thread != LLDB_INVALID_HOST_THREAD) + ::CloseHandle(m_thread); + + HostNativeThreadBase::Reset(); +} |