2020-01-24 08:23:27 +01:00
|
|
|
//===-- HostThreadWindows.cpp ---------------------------------------------===//
|
2014-09-09 20:54:56 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-09-09 20:54:56 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
#include "lldb/Utility/Status.h"
|
2014-09-09 20:54:56 +00:00
|
|
|
|
|
|
|
|
#include "lldb/Host/windows/HostThreadWindows.h"
|
|
|
|
|
#include "lldb/Host/windows/windows.h"
|
|
|
|
|
|
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
2014-12-18 18:21:33 +00:00
|
|
|
namespace {
|
|
|
|
|
void __stdcall ExitThreadProxy(ULONG_PTR dwExitCode) {
|
|
|
|
|
::ExitThread(dwExitCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-09 20:54:56 +00:00
|
|
|
HostThreadWindows::HostThreadWindows()
|
|
|
|
|
: HostNativeThreadBase(), m_owns_handle(true) {}
|
|
|
|
|
|
|
|
|
|
HostThreadWindows::HostThreadWindows(lldb::thread_t thread)
|
|
|
|
|
: HostNativeThreadBase(thread), m_owns_handle(true) {}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-09-09 20:54:56 +00:00
|
|
|
HostThreadWindows::~HostThreadWindows() { Reset(); }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-11-05 22:16:28 +00:00
|
|
|
void HostThreadWindows::SetOwnsHandle(bool owns) { m_owns_handle = owns; }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status HostThreadWindows::Join(lldb::thread_result_t *result) {
|
|
|
|
|
Status error;
|
2014-09-23 18:32:09 +00:00
|
|
|
if (IsJoinable()) {
|
2014-11-05 22:16:28 +00:00
|
|
|
DWORD wait_result = ::WaitForSingleObject(m_thread, INFINITE);
|
2014-09-09 20:54:56 +00:00
|
|
|
if (WAIT_OBJECT_0 == wait_result && result) {
|
2014-09-23 18:32:09 +00:00
|
|
|
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);
|
2016-09-06 20:57:50 +00:00
|
|
|
} else
|
2014-09-23 18:32:09 +00:00
|
|
|
error.SetError(ERROR_INVALID_HANDLE, eErrorTypeWin32);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
|
|
|
|
Reset();
|
2014-09-09 20:54:56 +00:00
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status HostThreadWindows::Cancel() {
|
|
|
|
|
Status error;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-09-09 20:54:56 +00:00
|
|
|
DWORD result = ::QueueUserAPC(::ExitThreadProxy, m_thread, 0);
|
|
|
|
|
error.SetError(result, eErrorTypeWin32);
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-05 22:16:28 +00:00
|
|
|
lldb::tid_t HostThreadWindows::GetThreadId() const {
|
|
|
|
|
return ::GetThreadId(m_thread);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-09 20:54:56 +00:00
|
|
|
void HostThreadWindows::Reset() {
|
2014-09-23 18:32:09 +00:00
|
|
|
if (m_owns_handle && m_thread != LLDB_INVALID_HOST_THREAD)
|
|
|
|
|
::CloseHandle(m_thread);
|
2014-10-26 21:38:43 +00:00
|
|
|
|
2014-09-09 20:54:56 +00:00
|
|
|
HostNativeThreadBase::Reset();
|
|
|
|
|
}
|
2018-10-18 07:52:56 +00:00
|
|
|
|
|
|
|
|
bool HostThreadWindows::EqualsThread(lldb::thread_t thread) const {
|
|
|
|
|
return GetThreadId() == ::GetThreadId(thread);
|
|
|
|
|
}
|