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 | |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 10 | #include "lldb/Host/posix/HostThreadPosix.h" |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 11 | #include "lldb/Utility/Status.h" |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 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 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 19 | HostThreadPosix::HostThreadPosix() {} |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 20 | |
| 21 | HostThreadPosix::HostThreadPosix(lldb::thread_t thread) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 22 | : HostNativeThreadBase(thread) {} |
| 23 | |
| 24 | HostThreadPosix::~HostThreadPosix() {} |
| 25 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 26 | Status HostThreadPosix::Join(lldb::thread_result_t *result) { |
| 27 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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; |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 41 | Status HostThreadPosix::Cancel() { |
| 42 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 43 | if (IsJoinable()) { |
Ed Maste | 718e296 | 2016-05-13 17:01:59 +0000 | [diff] [blame] | 44 | #ifndef __FreeBSD__ |
Davide Italiano | c12c0c5 | 2017-11-15 23:39:41 +0000 | [diff] [blame] | 45 | llvm_unreachable("someone is calling HostThread::Cancel()"); |
Pavel Labath | 408b0f5 | 2018-03-06 12:46:05 +0000 | [diff] [blame] | 46 | #else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | int err = ::pthread_cancel(m_thread); |
| 48 | error.SetError(err, eErrorTypePOSIX); |
Todd Fiala | cacde7d | 2014-09-27 16:54:22 +0000 | [diff] [blame] | 49 | #endif |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | } |
| 51 | return error; |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 54 | Status HostThreadPosix::Detach() { |
| 55 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | if (IsJoinable()) { |
| 57 | int err = ::pthread_detach(m_thread); |
| 58 | error.SetError(err, eErrorTypePOSIX); |
| 59 | } |
| 60 | Reset(); |
| 61 | return error; |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 62 | } |