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 bool HostNativeThreadBase::EqualsThread(lldb::thread_t thread) const { 45 return m_thread == thread; 46 } 47 48 lldb::thread_t HostNativeThreadBase::Release() { 49 lldb::thread_t result = m_thread; 50 m_thread = LLDB_INVALID_HOST_THREAD; 51 m_result = 0; 52 53 return result; 54 } 55 56 lldb::thread_result_t 57 HostNativeThreadBase::ThreadCreateTrampoline(lldb::thread_arg_t arg) { 58 ThreadLauncher::HostThreadCreateInfo *info = 59 (ThreadLauncher::HostThreadCreateInfo *)arg; 60 llvm::set_thread_name(info->thread_name); 61 62 thread_func_t thread_fptr = info->thread_fptr; 63 thread_arg_t thread_arg = info->thread_arg; 64 65 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD)); 66 if (log) 67 log->Printf("thread created"); 68 69 delete info; 70 return thread_fptr(thread_arg); 71 } 72