]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Host/posix/HostThreadPosix.cpp
MFV r323912: 8592 ZFS channel programs - rollback
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Host / posix / HostThreadPosix.cpp
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
19 HostThreadPosix::HostThreadPosix() {}
20
21 HostThreadPosix::HostThreadPosix(lldb::thread_t thread)
22     : HostNativeThreadBase(thread) {}
23
24 HostThreadPosix::~HostThreadPosix() {}
25
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
41 Status HostThreadPosix::Cancel() {
42   Status error;
43   if (IsJoinable()) {
44 #ifndef __ANDROID__
45 #ifndef __FreeBSD__
46     assert(false && "someone is calling HostThread::Cancel()");
47 #endif
48     int err = ::pthread_cancel(m_thread);
49     error.SetError(err, eErrorTypePOSIX);
50 #else
51     error.SetErrorString("HostThreadPosix::Cancel() not supported on Android");
52 #endif
53   }
54   return error;
55 }
56
57 Status HostThreadPosix::Detach() {
58   Status error;
59   if (IsJoinable()) {
60     int err = ::pthread_detach(m_thread);
61     error.SetError(err, eErrorTypePOSIX);
62   }
63   Reset();
64   return error;
65 }