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         int err = ::pthread_join(m_thread, result);
39         error.SetError(err, lldb::eErrorTypePOSIX);
40     }
41     else
42     {
43         if (result)
44             *result = NULL;
45         error.SetError(EINVAL, eErrorTypePOSIX);
46     }
47 
48     Reset();
49     return error;
50 }
51 
52 Error
53 HostThreadPosix::Cancel()
54 {
55     Error error;
56 #ifndef __ANDROID__
57     int err = ::pthread_cancel(m_thread);
58     error.SetError(err, eErrorTypePOSIX);
59 #else
60     error.SetErrorString("HostThreadPosix::Cancel() not supported on Android");
61 #endif
62 
63     return error;
64 }
65 
66 Error
67 HostThreadPosix::Detach()
68 {
69     Error error;
70     int err = ::pthread_detach(m_thread);
71     error.SetError(err, eErrorTypePOSIX);
72     Reset();
73     return error;
74 }
75