1 //===-- HostThreadPosix.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/Error.h" 11 #include "lldb/Host/posix/HostThreadPosix.h" 12 13 #include <errno.h> 14 #include <pthread.h> 15 16 using namespace lldb; 17 using namespace lldb_private; 18 19 HostThreadPosix::HostThreadPosix() 20 { 21 } 22 23 HostThreadPosix::HostThreadPosix(lldb::thread_t thread) 24 : HostNativeThreadBase(thread) 25 { 26 } 27 28 HostThreadPosix::~HostThreadPosix() 29 { 30 } 31 32 Error 33 HostThreadPosix::Join(lldb::thread_result_t *result) 34 { 35 Error error; 36 if (IsJoinable()) 37 { 38 lldb::thread_result_t thread_result; 39 int err = ::pthread_join(m_thread, &thread_result); 40 error.SetError(err, lldb::eErrorTypePOSIX); 41 } 42 else 43 error.SetError(EINVAL, eErrorTypePOSIX); 44 45 Reset(); 46 return error; 47 } 48 49 Error 50 HostThreadPosix::Cancel() 51 { 52 Error error; 53 #ifndef __ANDROID__ 54 int err = ::pthread_cancel(m_thread); 55 error.SetError(err, eErrorTypePOSIX); 56 #else 57 error.SetErrorString("HostThreadPosix::Cancel() not supported on Android"); 58 #endif 59 60 return error; 61 } 62 63 Error 64 HostThreadPosix::Detach() 65 { 66 Error error; 67 int err = ::pthread_detach(m_thread); 68 error.SetError(err, eErrorTypePOSIX); 69 Reset(); 70 return error; 71 } 72