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/Host/posix/HostThreadPosix.h"
11 #include "lldb/Utility/Status.h"
12 
13 #include <errno.h>
14 #include <pthread.h>
15 
16 using namespace lldb;
17 using namespace lldb_private;
18 
HostThreadPosix()19 HostThreadPosix::HostThreadPosix() {}
20 
HostThreadPosix(lldb::thread_t thread)21 HostThreadPosix::HostThreadPosix(lldb::thread_t thread)
22     : HostNativeThreadBase(thread) {}
23 
~HostThreadPosix()24 HostThreadPosix::~HostThreadPosix() {}
25 
Join(lldb::thread_result_t * result)26 Status HostThreadPosix::Join(lldb::thread_result_t *result) {
27   Status error;
28   if (IsJoinable()) {
29     int err = ::pthread_join(m_thread, result);
30     error.SetError(err, lldb::eErrorTypePOSIX);
31   } else {
32     if (result)
33       *result = NULL;
34     error.SetError(EINVAL, eErrorTypePOSIX);
35   }
36 
37   Reset();
38   return error;
39 }
40 
Cancel()41 Status HostThreadPosix::Cancel() {
42   Status error;
43   if (IsJoinable()) {
44 #ifndef __FreeBSD__
45     llvm_unreachable("someone is calling HostThread::Cancel()");
46 #else
47     int err = ::pthread_cancel(m_thread);
48     error.SetError(err, eErrorTypePOSIX);
49 #endif
50   }
51   return error;
52 }
53 
Detach()54 Status HostThreadPosix::Detach() {
55   Status error;
56   if (IsJoinable()) {
57     int err = ::pthread_detach(m_thread);
58     error.SetError(err, eErrorTypePOSIX);
59   }
60   Reset();
61   return error;
62 }
63