]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/source/Host/common/HostNativeThreadBase.cpp
Move all sources from the llvm project into contrib/llvm-project.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / source / Host / common / HostNativeThreadBase.cpp
1 //===-- HostNativeThreadBase.cpp --------------------------------*- C++ -*-===//
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()
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 bool HostNativeThreadBase::EqualsThread(lldb::thread_t thread) const {
44   return m_thread == thread;
45 }
46
47 lldb::thread_t HostNativeThreadBase::Release() {
48   lldb::thread_t result = m_thread;
49   m_thread = LLDB_INVALID_HOST_THREAD;
50   m_result = 0;
51
52   return result;
53 }
54
55 lldb::thread_result_t
56 HostNativeThreadBase::ThreadCreateTrampoline(lldb::thread_arg_t arg) {
57   ThreadLauncher::HostThreadCreateInfo *info =
58       (ThreadLauncher::HostThreadCreateInfo *)arg;
59   llvm::set_thread_name(info->thread_name);
60
61   thread_func_t thread_fptr = info->thread_fptr;
62   thread_arg_t thread_arg = info->thread_arg;
63
64   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
65   if (log)
66     log->Printf("thread created");
67
68   delete info;
69   return thread_fptr(thread_arg);
70 }