blob: 4e62ad5abce492bbe464b9c37628ff185e066a69 [file] [log] [blame]
Zachary Turner39de3112014-09-09 20:54:56 +00001//===-- 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
15using namespace lldb_private;
16
17HostThreadPosix::HostThreadPosix()
18{
19}
20
21HostThreadPosix::HostThreadPosix(lldb::thread_t thread)
22 : HostNativeThreadBase(thread)
23{
24}
25
26HostThreadPosix::~HostThreadPosix()
27{
28}
29
30Error
31HostThreadPosix::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
44Error
45HostThreadPosix::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
56Error
57HostThreadPosix::Detach()
58{
59 Error error;
60 int err = ::pthread_detach(m_thread);
61 error.SetError(err, lldb::eErrorTypePOSIX);
62 return error;
63}