xref: /llvm-project/lldb/source/Host/common/HostNativeThreadBase.cpp (revision 771ef6d4f15452d76387cd66552a38122be60925)
1 //===-- HostNativeThreadBase.cpp --------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/Host/HostNativeThreadBase.h"
11 #include "lldb/Core/Log.h"
12 #include "lldb/Host/HostInfo.h"
13 #include "lldb/Host/ThisThread.h"
14 #include "lldb/Host/ThreadLauncher.h"
15 #include "llvm/ADT/StringExtras.h"
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
20 HostNativeThreadBase::HostNativeThreadBase()
21     : m_thread(LLDB_INVALID_HOST_THREAD), m_result(0) {}
22 
23 HostNativeThreadBase::HostNativeThreadBase(thread_t thread)
24     : m_thread(thread), m_result(0) {}
25 
26 lldb::thread_t HostNativeThreadBase::GetSystemHandle() const {
27   return m_thread;
28 }
29 
30 lldb::thread_result_t HostNativeThreadBase::GetResult() const {
31   return m_result;
32 }
33 
34 bool HostNativeThreadBase::IsJoinable() const {
35   return m_thread != LLDB_INVALID_HOST_THREAD;
36 }
37 
38 void HostNativeThreadBase::Reset() {
39   m_thread = LLDB_INVALID_HOST_THREAD;
40   m_result = 0;
41 }
42 
43 lldb::thread_t HostNativeThreadBase::Release() {
44   lldb::thread_t result = m_thread;
45   m_thread = LLDB_INVALID_HOST_THREAD;
46   m_result = 0;
47 
48   return result;
49 }
50 
51 lldb::thread_result_t
52 HostNativeThreadBase::ThreadCreateTrampoline(lldb::thread_arg_t arg) {
53   ThreadLauncher::HostThreadCreateInfo *info =
54       (ThreadLauncher::HostThreadCreateInfo *)arg;
55   ThisThread::SetName(info->thread_name, HostInfo::GetMaxThreadNameLength());
56 
57   thread_func_t thread_fptr = info->thread_fptr;
58   thread_arg_t thread_arg = info->thread_arg;
59 
60   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
61   if (log)
62     log->Printf("thread created");
63 
64   delete info;
65   return thread_fptr(thread_arg);
66 }
67