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/Core/Log.h" 11 #include "lldb/Host/HostInfo.h" 12 #include "lldb/Host/HostNativeThreadBase.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) 22 , m_result(0) 23 { 24 } 25 26 HostNativeThreadBase::HostNativeThreadBase(thread_t thread) 27 : m_thread(thread) 28 , m_result(0) 29 { 30 } 31 32 lldb::thread_t 33 HostNativeThreadBase::GetSystemHandle() const 34 { 35 return m_thread; 36 } 37 38 lldb::thread_result_t 39 HostNativeThreadBase::GetResult() const 40 { 41 return m_result; 42 } 43 44 bool 45 HostNativeThreadBase::IsJoinable() const 46 { 47 return m_thread != LLDB_INVALID_HOST_THREAD; 48 } 49 50 void 51 HostNativeThreadBase::Reset() 52 { 53 m_thread = LLDB_INVALID_HOST_THREAD; 54 m_result = 0; 55 } 56 57 lldb::thread_t 58 HostNativeThreadBase::Release() 59 { 60 lldb::thread_t result = m_thread; 61 m_thread = LLDB_INVALID_HOST_THREAD; 62 m_result = 0; 63 64 return result; 65 } 66 67 lldb::thread_result_t 68 HostNativeThreadBase::ThreadCreateTrampoline(lldb::thread_arg_t arg) 69 { 70 ThreadLauncher::HostThreadCreateInfo *info = (ThreadLauncher::HostThreadCreateInfo *)arg; 71 ThisThread::SetName(info->thread_name.c_str(), HostInfo::GetMaxThreadNameLength()); 72 73 thread_func_t thread_fptr = info->thread_fptr; 74 thread_arg_t thread_arg = info->thread_arg; 75 76 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD)); 77 if (log) 78 log->Printf("thread created"); 79 80 delete info; 81 return thread_fptr(thread_arg); 82 } 83