LLDB  mainline
HostThreadWindows.cpp
Go to the documentation of this file.
1 //===-- HostThreadWindows.cpp ---------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "lldb/Utility/Status.h"
10 
13 
14 #include "llvm/ADT/STLExtras.h"
15 
16 using namespace lldb;
17 using namespace lldb_private;
18 
19 static void __stdcall ExitThreadProxy(ULONG_PTR dwExitCode) {
20  ::ExitThread(dwExitCode);
21 }
22 
23 HostThreadWindows::HostThreadWindows()
24  : HostNativeThreadBase(), m_owns_handle(true) {}
25 
27  : HostNativeThreadBase(thread), m_owns_handle(true) {}
28 
30 
32 
34  Status error;
35  if (IsJoinable()) {
36  DWORD wait_result = ::WaitForSingleObject(m_thread, INFINITE);
37  if (WAIT_OBJECT_0 == wait_result && result) {
38  DWORD exit_code = 0;
39  if (!::GetExitCodeThread(m_thread, &exit_code))
40  *result = 0;
41  *result = exit_code;
42  } else if (WAIT_OBJECT_0 != wait_result)
43  error.SetError(::GetLastError(), eErrorTypeWin32);
44  } else
45  error.SetError(ERROR_INVALID_HANDLE, eErrorTypeWin32);
46 
47  Reset();
48  return error;
49 }
50 
52  Status error;
53 
54  DWORD result = ::QueueUserAPC(::ExitThreadProxy, m_thread, 0);
55  error.SetError(result, eErrorTypeWin32);
56  return error;
57 }
58 
60  return ::GetThreadId(m_thread);
61 }
62 
65  ::CloseHandle(m_thread);
66 
68 }
69 
71  return GetThreadId() == ::GetThreadId(thread);
72 }
lldb_private::HostThreadWindows::EqualsThread
bool EqualsThread(lldb::thread_t thread) const override
Definition: HostThreadWindows.cpp:70
lldb_private::HostNativeThreadBase
Definition: HostNativeThreadBase.h:24
lldb::eErrorTypeWin32
@ eErrorTypeWin32
Standard Win32 error codes.
Definition: lldb-enumerations.h:312
lldb_private::HostThreadWindows::HostThreadWindows
HostThreadWindows()
Definition: HostThreadWindows.cpp:23
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb::thread_t
pthread_t thread_t
Definition: lldb-types.h:58
lldb_private::HostThreadWindows::~HostThreadWindows
virtual ~HostThreadWindows()
Definition: HostThreadWindows.cpp:29
lldb_private::HostThreadWindows::m_owns_handle
bool m_owns_handle
Definition: HostThreadWindows.h:37
lldb_private::HostNativeThreadBase::IsJoinable
virtual bool IsJoinable() const
Definition: HostNativeThreadBase.cpp:31
lldb_private::Status
Definition: Status.h:44
lldb::thread_result_t
void * thread_result_t
Definition: lldb-types.h:62
lldb_private::HostThreadWindows::GetThreadId
lldb::tid_t GetThreadId() const
Definition: HostThreadWindows.cpp:59
windows.h
lldb_private::HostNativeThreadBase::Reset
virtual void Reset()
Definition: HostNativeThreadBase.cpp:35
lldb_private::HostThreadWindows::Cancel
Status Cancel() override
Definition: HostThreadWindows.cpp:51
Status.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::HostThreadWindows::Join
Status Join(lldb::thread_result_t *result) override
Definition: HostThreadWindows.cpp:33
ExitThreadProxy
static void __stdcall ExitThreadProxy(ULONG_PTR dwExitCode)
Definition: HostThreadWindows.cpp:19
lldb_private::HostNativeThreadBase::m_thread
lldb::thread_t m_thread
Definition: HostNativeThreadBase.h:48
lldb_private::HostThreadWindows::Reset
void Reset() override
Definition: HostThreadWindows.cpp:63
lldb_private::HostThreadWindows::SetOwnsHandle
void SetOwnsHandle(bool owns)
Definition: HostThreadWindows.cpp:31
lldb
Definition: SBAddress.h:15
HostThreadWindows.h
LLDB_INVALID_HOST_THREAD
#define LLDB_INVALID_HOST_THREAD
Definition: lldb-types.h:79
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86