Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 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 | |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 13 | #include <errno.h> |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 14 | #include <pthread.h> |
| 15 | |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 16 | using namespace lldb; |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 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; |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 36 | if (IsJoinable()) |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 37 | { |
Greg Clayton | 62f24e9 | 2015-01-06 00:21:29 +0000 | [diff] [blame^] | 38 | int err = ::pthread_join(m_thread, result); |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 39 | error.SetError(err, lldb::eErrorTypePOSIX); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 40 | } |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 41 | else |
Greg Clayton | 62f24e9 | 2015-01-06 00:21:29 +0000 | [diff] [blame^] | 42 | { |
| 43 | if (result) |
| 44 | *result = NULL; |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 45 | error.SetError(EINVAL, eErrorTypePOSIX); |
Greg Clayton | 62f24e9 | 2015-01-06 00:21:29 +0000 | [diff] [blame^] | 46 | } |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 47 | |
| 48 | Reset(); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 49 | return error; |
| 50 | } |
| 51 | |
| 52 | Error |
| 53 | HostThreadPosix::Cancel() |
| 54 | { |
| 55 | Error error; |
Todd Fiala | cacde7d | 2014-09-27 16:54:22 +0000 | [diff] [blame] | 56 | #ifndef __ANDROID__ |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 57 | int err = ::pthread_cancel(m_thread); |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 58 | error.SetError(err, eErrorTypePOSIX); |
Todd Fiala | cacde7d | 2014-09-27 16:54:22 +0000 | [diff] [blame] | 59 | #else |
| 60 | error.SetErrorString("HostThreadPosix::Cancel() not supported on Android"); |
| 61 | #endif |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 62 | |
| 63 | return error; |
| 64 | } |
| 65 | |
| 66 | Error |
| 67 | HostThreadPosix::Detach() |
| 68 | { |
| 69 | Error error; |
| 70 | int err = ::pthread_detach(m_thread); |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 71 | error.SetError(err, eErrorTypePOSIX); |
| 72 | Reset(); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 73 | return error; |
| 74 | } |