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 | { |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 38 | lldb::thread_result_t thread_result; |
| 39 | int err = ::pthread_join(m_thread, &thread_result); |
| 40 | error.SetError(err, lldb::eErrorTypePOSIX); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 41 | } |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 42 | else |
| 43 | error.SetError(EINVAL, eErrorTypePOSIX); |
| 44 | |
| 45 | Reset(); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 46 | return error; |
| 47 | } |
| 48 | |
| 49 | Error |
| 50 | HostThreadPosix::Cancel() |
| 51 | { |
| 52 | Error error; |
Todd Fiala | cacde7d | 2014-09-27 16:54:22 +0000 | [diff] [blame] | 53 | #ifndef __ANDROID__ |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 54 | int err = ::pthread_cancel(m_thread); |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 55 | error.SetError(err, eErrorTypePOSIX); |
Todd Fiala | cacde7d | 2014-09-27 16:54:22 +0000 | [diff] [blame] | 56 | #else |
| 57 | error.SetErrorString("HostThreadPosix::Cancel() not supported on Android"); |
| 58 | #endif |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 59 | |
| 60 | return error; |
| 61 | } |
| 62 | |
| 63 | Error |
| 64 | HostThreadPosix::Detach() |
| 65 | { |
| 66 | Error error; |
| 67 | int err = ::pthread_detach(m_thread); |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 68 | error.SetError(err, eErrorTypePOSIX); |
| 69 | Reset(); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 70 | return error; |
| 71 | } |