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/Core/Log.h" 12 #include "lldb/Host/HostInfo.h" 13 #include "lldb/Host/ThisThread.h" 14 #include "lldb/Host/ThreadLauncher.h" 15 #include "llvm/ADT/StringExtras.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 lldb::thread_t HostNativeThreadBase::Release() { 44 lldb::thread_t result = m_thread; 45 m_thread = LLDB_INVALID_HOST_THREAD; 46 m_result = 0; 47 48 return result; 49 } 50 51 lldb::thread_result_t 52 HostNativeThreadBase::ThreadCreateTrampoline(lldb::thread_arg_t arg) { 53 ThreadLauncher::HostThreadCreateInfo *info = 54 (ThreadLauncher::HostThreadCreateInfo *)arg; 55 ThisThread::SetName(info->thread_name.c_str(), 56 HostInfo::GetMaxThreadNameLength()); 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