xref: /freebsd/contrib/llvm-project/lldb/source/Host/common/HostNativeThreadBase.cpp (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
1 //===-- HostNativeThreadBase.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/Host/HostNativeThreadBase.h"
10 #include "lldb/Host/HostInfo.h"
11 #include "lldb/Host/ThreadLauncher.h"
12 #include "lldb/Utility/Log.h"
13 
14 #include "llvm/ADT/StringExtras.h"
15 #include "llvm/Support/Threading.h"
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
20 HostNativeThreadBase::HostNativeThreadBase(thread_t thread)
21     : m_thread(thread), m_result(0) {} // NOLINT(modernize-use-nullptr)
22 
23 lldb::thread_t HostNativeThreadBase::GetSystemHandle() const {
24   return m_thread;
25 }
26 
27 lldb::thread_result_t HostNativeThreadBase::GetResult() const {
28   return m_result;
29 }
30 
31 bool HostNativeThreadBase::IsJoinable() const {
32   return m_thread != LLDB_INVALID_HOST_THREAD;
33 }
34 
35 void HostNativeThreadBase::Reset() {
36   m_thread = LLDB_INVALID_HOST_THREAD;
37   m_result = 0; // NOLINT(modernize-use-nullptr)
38 }
39 
40 bool HostNativeThreadBase::EqualsThread(lldb::thread_t thread) const {
41   return m_thread == thread;
42 }
43 
44 lldb::thread_t HostNativeThreadBase::Release() {
45   lldb::thread_t result = m_thread;
46   m_thread = LLDB_INVALID_HOST_THREAD;
47   m_result = 0; // NOLINT(modernize-use-nullptr)
48 
49   return result;
50 }
51 
52 lldb::thread_result_t
53 HostNativeThreadBase::ThreadCreateTrampoline(lldb::thread_arg_t arg) {
54   ThreadLauncher::HostThreadCreateInfo *info =
55       (ThreadLauncher::HostThreadCreateInfo *)arg;
56   llvm::set_thread_name(info->thread_name);
57 
58   thread_func_t thread_fptr = info->thread_fptr;
59   thread_arg_t thread_arg = info->thread_arg;
60 
61   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
62   LLDB_LOGF(log, "thread created");
63 
64   delete info;
65   return thread_fptr(thread_arg);
66 }
67