blob: 9c4892431938886878a925ccefc7e44928228def [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
Zachary Turneracee96a2014-09-23 18:32:09 +000013#include <errno.h>
Zachary Turner39de3112014-09-09 20:54:56 +000014#include <pthread.h>
15
Zachary Turneracee96a2014-09-23 18:32:09 +000016using namespace lldb;
Zachary Turner39de3112014-09-09 20:54:56 +000017using namespace lldb_private;
18
19HostThreadPosix::HostThreadPosix()
20{
21}
22
23HostThreadPosix::HostThreadPosix(lldb::thread_t thread)
24 : HostNativeThreadBase(thread)
25{
26}
27
28HostThreadPosix::~HostThreadPosix()
29{
30}
31
32Error
33HostThreadPosix::Join(lldb::thread_result_t *result)
34{
35 Error error;
Zachary Turneracee96a2014-09-23 18:32:09 +000036 if (IsJoinable())
Zachary Turner39de3112014-09-09 20:54:56 +000037 {
Greg Clayton62f24e92015-01-06 00:21:29 +000038 int err = ::pthread_join(m_thread, result);
Zachary Turneracee96a2014-09-23 18:32:09 +000039 error.SetError(err, lldb::eErrorTypePOSIX);
Zachary Turner39de3112014-09-09 20:54:56 +000040 }
Zachary Turneracee96a2014-09-23 18:32:09 +000041 else
Greg Clayton62f24e92015-01-06 00:21:29 +000042 {
43 if (result)
44 *result = NULL;
Zachary Turneracee96a2014-09-23 18:32:09 +000045 error.SetError(EINVAL, eErrorTypePOSIX);
Greg Clayton62f24e92015-01-06 00:21:29 +000046 }
Zachary Turneracee96a2014-09-23 18:32:09 +000047
48 Reset();
Zachary Turner39de3112014-09-09 20:54:56 +000049 return error;
50}
51
52Error
53HostThreadPosix::Cancel()
54{
55 Error error;
Todd Fialacacde7d2014-09-27 16:54:22 +000056#ifndef __ANDROID__
Zachary Turner39de3112014-09-09 20:54:56 +000057 int err = ::pthread_cancel(m_thread);
Zachary Turneracee96a2014-09-23 18:32:09 +000058 error.SetError(err, eErrorTypePOSIX);
Todd Fialacacde7d2014-09-27 16:54:22 +000059#else
60 error.SetErrorString("HostThreadPosix::Cancel() not supported on Android");
61#endif
Zachary Turner39de3112014-09-09 20:54:56 +000062
63 return error;
64}
65
66Error
67HostThreadPosix::Detach()
68{
69 Error error;
70 int err = ::pthread_detach(m_thread);
Zachary Turneracee96a2014-09-23 18:32:09 +000071 error.SetError(err, eErrorTypePOSIX);
72 Reset();
Zachary Turner39de3112014-09-09 20:54:56 +000073 return error;
74}