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_state(eThreadStateInvalid) 23 , m_result(0) 24 { 25 } 26 27 HostNativeThreadBase::HostNativeThreadBase(thread_t thread) 28 : m_thread(thread) 29 , m_state((thread == LLDB_INVALID_HOST_THREAD) ? eThreadStateInvalid : eThreadStateRunning) 30 , m_result(0) 31 { 32 } 33 34 void 35 HostNativeThreadBase::SetState(ThreadState state) 36 { 37 m_state = state; 38 } 39 40 ThreadState 41 HostNativeThreadBase::GetState() const 42 { 43 return m_state; 44 } 45 46 lldb::thread_t 47 HostNativeThreadBase::GetSystemHandle() const 48 { 49 return m_thread; 50 } 51 52 lldb::thread_result_t 53 HostNativeThreadBase::GetResult() const 54 { 55 return m_result; 56 } 57 58 void 59 HostNativeThreadBase::Reset() 60 { 61 m_thread = LLDB_INVALID_HOST_THREAD; 62 m_state = eThreadStateInvalid; 63 m_result = 0; 64 } 65 66 lldb::thread_t 67 HostNativeThreadBase::Release() 68 { 69 lldb::thread_t result = m_thread; 70 m_thread = LLDB_INVALID_HOST_THREAD; 71 m_state = eThreadStateInvalid; 72 m_result = 0; 73 74 return result; 75 } 76 77 lldb::thread_result_t 78 HostNativeThreadBase::ThreadCreateTrampoline(lldb::thread_arg_t arg) 79 { 80 ThreadLauncher::HostThreadCreateInfo *info = (ThreadLauncher::HostThreadCreateInfo *)arg; 81 ThisThread::SetName(info->thread_name.c_str(), HostInfo::GetMaxThreadNameLength()); 82 83 thread_func_t thread_fptr = info->thread_fptr; 84 thread_arg_t thread_arg = info->thread_arg; 85 86 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD)); 87 if (log) 88 log->Printf("thread created"); 89 90 delete info; 91 return thread_fptr(thread_arg); 92 } 93