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 | |
| 13 | #include <pthread.h> |
| 14 | |
| 15 | using namespace lldb_private; |
| 16 | |
| 17 | HostThreadPosix::HostThreadPosix() |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | HostThreadPosix::HostThreadPosix(lldb::thread_t thread) |
| 22 | : HostNativeThreadBase(thread) |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | HostThreadPosix::~HostThreadPosix() |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | Error |
| 31 | HostThreadPosix::Join(lldb::thread_result_t *result) |
| 32 | { |
| 33 | Error error; |
| 34 | lldb::thread_result_t thread_result; |
| 35 | int err = ::pthread_join(m_thread, &thread_result); |
| 36 | error.SetError(err, lldb::eErrorTypePOSIX); |
| 37 | if (err == 0) |
| 38 | { |
| 39 | m_state = (m_state == eThreadStateCancelling) ? eThreadStateCancelled : eThreadStateExited; |
| 40 | } |
| 41 | return error; |
| 42 | } |
| 43 | |
| 44 | Error |
| 45 | HostThreadPosix::Cancel() |
| 46 | { |
| 47 | Error error; |
| 48 | int err = ::pthread_cancel(m_thread); |
| 49 | error.SetError(err, lldb::eErrorTypePOSIX); |
| 50 | if (err == 0) |
| 51 | m_state = eThreadStateCancelling; |
| 52 | |
| 53 | return error; |
| 54 | } |
| 55 | |
| 56 | Error |
| 57 | HostThreadPosix::Detach() |
| 58 | { |
| 59 | Error error; |
| 60 | int err = ::pthread_detach(m_thread); |
| 61 | error.SetError(err, lldb::eErrorTypePOSIX); |
| 62 | return error; |
| 63 | } |