1 //===-- HostNativeThreadBase.cpp --------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Host/HostNativeThreadBase.h"
10 #include "lldb/Host/HostInfo.h"
11 #include "lldb/Host/ThreadLauncher.h"
12 #include "lldb/Utility/Log.h"
14 #include "llvm/ADT/StringExtras.h"
15 #include "llvm/Support/Threading.h"
18 using namespace lldb_private;
20 HostNativeThreadBase::HostNativeThreadBase()
21 : m_thread(LLDB_INVALID_HOST_THREAD), m_result(0) {}
23 HostNativeThreadBase::HostNativeThreadBase(thread_t thread)
24 : m_thread(thread), m_result(0) {}
26 lldb::thread_t HostNativeThreadBase::GetSystemHandle() const {
30 lldb::thread_result_t HostNativeThreadBase::GetResult() const {
34 bool HostNativeThreadBase::IsJoinable() const {
35 return m_thread != LLDB_INVALID_HOST_THREAD;
38 void HostNativeThreadBase::Reset() {
39 m_thread = LLDB_INVALID_HOST_THREAD;
43 bool HostNativeThreadBase::EqualsThread(lldb::thread_t thread) const {
44 return m_thread == thread;
47 lldb::thread_t HostNativeThreadBase::Release() {
48 lldb::thread_t result = m_thread;
49 m_thread = LLDB_INVALID_HOST_THREAD;
56 HostNativeThreadBase::ThreadCreateTrampoline(lldb::thread_arg_t arg) {
57 ThreadLauncher::HostThreadCreateInfo *info =
58 (ThreadLauncher::HostThreadCreateInfo *)arg;
59 llvm::set_thread_name(info->thread_name);
61 thread_func_t thread_fptr = info->thread_fptr;
62 thread_arg_t thread_arg = info->thread_arg;
64 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
66 log->Printf("thread created");
69 return thread_fptr(thread_arg);