HostNativeThreadBase.cpp revision 360784
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
17using namespace lldb;
18using namespace lldb_private;
19
20HostNativeThreadBase::HostNativeThreadBase()
21    : m_thread(LLDB_INVALID_HOST_THREAD), m_result(0) {}
22
23HostNativeThreadBase::HostNativeThreadBase(thread_t thread)
24    : m_thread(thread), m_result(0) {}
25
26lldb::thread_t HostNativeThreadBase::GetSystemHandle() const {
27  return m_thread;
28}
29
30lldb::thread_result_t HostNativeThreadBase::GetResult() const {
31  return m_result;
32}
33
34bool HostNativeThreadBase::IsJoinable() const {
35  return m_thread != LLDB_INVALID_HOST_THREAD;
36}
37
38void HostNativeThreadBase::Reset() {
39  m_thread = LLDB_INVALID_HOST_THREAD;
40  m_result = 0;
41}
42
43bool HostNativeThreadBase::EqualsThread(lldb::thread_t thread) const {
44  return m_thread == thread;
45}
46
47lldb::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
55lldb::thread_result_t
56HostNativeThreadBase::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  LLDB_LOGF(log, "thread created");
66
67  delete info;
68  return thread_fptr(thread_arg);
69}
70