2014-09-10 04:54:56 +08:00
|
|
|
//===-- 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()
|
2014-11-06 06:16:28 +08:00
|
|
|
, m_owns_handle(true)
|
2014-09-10 04:54:56 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
HostThreadWindows::HostThreadWindows(lldb::thread_t thread)
|
|
|
|
: HostNativeThreadBase(thread)
|
2014-11-06 06:16:28 +08:00
|
|
|
, m_owns_handle(true)
|
2014-09-10 04:54:56 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
HostThreadWindows::~HostThreadWindows()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
2014-11-06 06:16:28 +08:00
|
|
|
void
|
|
|
|
HostThreadWindows::SetOwnsHandle(bool owns)
|
|
|
|
{
|
|
|
|
m_owns_handle = owns;
|
|
|
|
}
|
|
|
|
|
2014-09-10 04:54:56 +08:00
|
|
|
Error
|
|
|
|
HostThreadWindows::Join(lldb::thread_result_t *result)
|
|
|
|
{
|
|
|
|
Error error;
|
2014-09-24 02:32:09 +08:00
|
|
|
if (IsJoinable())
|
2014-09-10 04:54:56 +08:00
|
|
|
{
|
2014-09-24 02:32:09 +08:00
|
|
|
DWORD wait_result = ::WaitForSingleObject(m_thread, INFINITE);
|
|
|
|
if (WAIT_OBJECT_0 == wait_result && result)
|
|
|
|
{
|
|
|
|
DWORD exit_code = 0;
|
|
|
|
if (!::GetExitCodeThread(m_thread, &exit_code))
|
|
|
|
*result = 0;
|
|
|
|
*result = exit_code;
|
|
|
|
}
|
|
|
|
else if (WAIT_OBJECT_0 != wait_result)
|
|
|
|
error.SetError(::GetLastError(), eErrorTypeWin32);
|
2014-09-10 04:54:56 +08:00
|
|
|
}
|
2014-09-24 02:32:09 +08:00
|
|
|
else
|
|
|
|
error.SetError(ERROR_INVALID_HANDLE, eErrorTypeWin32);
|
2014-10-27 05:38:43 +08:00
|
|
|
|
|
|
|
Reset ();
|
2014-09-10 04:54:56 +08:00
|
|
|
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()
|
|
|
|
{
|
2014-11-06 06:16:28 +08:00
|
|
|
if (m_owns_handle && m_thread != LLDB_INVALID_HOST_THREAD)
|
2014-09-10 04:54:56 +08:00
|
|
|
::CloseHandle(m_thread);
|
|
|
|
|
|
|
|
HostNativeThreadBase::Reset();
|
|
|
|
}
|