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 namespace {
20 void __stdcall ExitThreadProxy(ULONG_PTR dwExitCode) {
21  ::ExitThread(dwExitCode);
22 }
23 }
24 
25 HostThreadWindows::HostThreadWindows()
26  : HostNativeThreadBase(), m_owns_handle(true) {}
27 
29  : HostNativeThreadBase(thread), m_owns_handle(true) {}
30 
32 
34 
36  Status error;
37  if (IsJoinable()) {
38  DWORD wait_result = ::WaitForSingleObject(m_thread, INFINITE);
39  if (WAIT_OBJECT_0 == wait_result && result) {
40  DWORD exit_code = 0;
41  if (!::GetExitCodeThread(m_thread, &exit_code))
42  *result = 0;
43  *result = exit_code;
44  } else if (WAIT_OBJECT_0 != wait_result)
45  error.SetError(::GetLastError(), eErrorTypeWin32);
46  } else
47  error.SetError(ERROR_INVALID_HANDLE, eErrorTypeWin32);
48 
49  Reset();
50  return error;
51 }
52 
54  Status error;
55 
56  DWORD result = ::QueueUserAPC(::ExitThreadProxy, m_thread, 0);
57  error.SetError(result, eErrorTypeWin32);
58  return error;
59 }
60 
62  return ::GetThreadId(m_thread);
63 }
64 
67  ::CloseHandle(m_thread);
68 
70 }
71 
73  return GetThreadId() == ::GetThreadId(thread);
74 }
A class that represents a running process on the host machine.
virtual Status Join(lldb::thread_result_t *result)
Standard Win32 error codes.
static llvm::raw_ostream & error(Stream &strm)
uint64_t tid_t
Definition: lldb-types.h:86
pthread_t thread_t
Definition: lldb-types.h:58
virtual bool EqualsThread(lldb::thread_t thread) const
int void SetError(ValueType err, lldb::ErrorType type)
Set accessor with an error value and type.
Definition: Status.cpp:217
Definition: SBAddress.h:15
#define LLDB_INVALID_HOST_THREAD
Definition: lldb-types.h:79
An error handling class.
Definition: Status.h:44
void * thread_result_t
Definition: lldb-types.h:62