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; |
Greg Clayton | 1e20f02 | 2016-05-12 22:58:52 +0000 | [diff] [blame] | 56 | if (IsJoinable()) |
| 57 | { |
Todd Fiala | cacde7d | 2014-09-27 16:54:22 +0000 | [diff] [blame] | 58 | #ifndef __ANDROID__ |
Ed Maste | 718e296 | 2016-05-13 17:01:59 +0000 | [diff] [blame^] | 59 | #ifndef __FreeBSD__ |
Greg Clayton | 1e20f02 | 2016-05-12 22:58:52 +0000 | [diff] [blame] | 60 | assert(false && "someone is calling HostThread::Cancel()"); |
Ed Maste | 718e296 | 2016-05-13 17:01:59 +0000 | [diff] [blame^] | 61 | #endif |
Greg Clayton | 1e20f02 | 2016-05-12 22:58:52 +0000 | [diff] [blame] | 62 | int err = ::pthread_cancel(m_thread); |
| 63 | error.SetError(err, eErrorTypePOSIX); |
Todd Fiala | cacde7d | 2014-09-27 16:54:22 +0000 | [diff] [blame] | 64 | #else |
Greg Clayton | 1e20f02 | 2016-05-12 22:58:52 +0000 | [diff] [blame] | 65 | error.SetErrorString("HostThreadPosix::Cancel() not supported on Android"); |
Todd Fiala | cacde7d | 2014-09-27 16:54:22 +0000 | [diff] [blame] | 66 | #endif |
Greg Clayton | 1e20f02 | 2016-05-12 22:58:52 +0000 | [diff] [blame] | 67 | } |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 68 | return error; |
| 69 | } |
| 70 | |
| 71 | Error |
| 72 | HostThreadPosix::Detach() |
| 73 | { |
| 74 | Error error; |
Greg Clayton | 1e20f02 | 2016-05-12 22:58:52 +0000 | [diff] [blame] | 75 | if (IsJoinable()) |
| 76 | { |
| 77 | int err = ::pthread_detach(m_thread); |
| 78 | error.SetError(err, eErrorTypePOSIX); |
| 79 | } |
Zachary Turner | acee96a | 2014-09-23 18:32:09 +0000 | [diff] [blame] | 80 | Reset(); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 81 | return error; |
| 82 | } |