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/Host/HostInfo.h" 12 #include "lldb/Host/ThreadLauncher.h" 13 #include "lldb/Utility/Log.h" 14 15 #include "llvm/ADT/StringExtras.h" 16 #include "llvm/Support/Threading.h" 17 18 using namespace lldb; 19 using namespace lldb_private; 20 21 HostNativeThreadBase::HostNativeThreadBase() 22 : m_thread(LLDB_INVALID_HOST_THREAD), m_result(0) {} 23 24 HostNativeThreadBase::HostNativeThreadBase(thread_t thread) 25 : m_thread(thread), m_result(0) {} 26 27 lldb::thread_t HostNativeThreadBase::GetSystemHandle() const { 28 return m_thread; 29 } 30 31 lldb::thread_result_t HostNativeThreadBase::GetResult() const { 32 return m_result; 33 } 34 35 bool HostNativeThreadBase::IsJoinable() const { 36 return m_thread != LLDB_INVALID_HOST_THREAD; 37 } 38 39 void HostNativeThreadBase::Reset() { 40 m_thread = LLDB_INVALID_HOST_THREAD; 41 m_result = 0; 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; 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 if (log) 63 log->Printf("thread created"); 64 65 delete info; 66 return thread_fptr(thread_arg); 67 } 68