blob: 073b7b0b11e8ce9e2e3b04359dc913b5d20e70a0 [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
Zachary Turner39de3112014-09-09 20:54:56 +000010#include "lldb/Host/posix/HostThreadPosix.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000011#include "lldb/Utility/Error.h"
Zachary Turner39de3112014-09-09 20:54:56 +000012
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
Kate Stoneb9c1b512016-09-06 20:57:50 +000019HostThreadPosix::HostThreadPosix() {}
Zachary Turner39de3112014-09-09 20:54:56 +000020
21HostThreadPosix::HostThreadPosix(lldb::thread_t thread)
Kate Stoneb9c1b512016-09-06 20:57:50 +000022 : HostNativeThreadBase(thread) {}
23
24HostThreadPosix::~HostThreadPosix() {}
25
26Error HostThreadPosix::Join(lldb::thread_result_t *result) {
27 Error error;
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 Turner39de3112014-09-09 20:54:56 +000039}
40
Kate Stoneb9c1b512016-09-06 20:57:50 +000041Error HostThreadPosix::Cancel() {
42 Error error;
43 if (IsJoinable()) {
Todd Fialacacde7d2014-09-27 16:54:22 +000044#ifndef __ANDROID__
Ed Maste718e2962016-05-13 17:01:59 +000045#ifndef __FreeBSD__
Kate Stoneb9c1b512016-09-06 20:57:50 +000046 assert(false && "someone is calling HostThread::Cancel()");
Ed Maste718e2962016-05-13 17:01:59 +000047#endif
Kate Stoneb9c1b512016-09-06 20:57:50 +000048 int err = ::pthread_cancel(m_thread);
49 error.SetError(err, eErrorTypePOSIX);
Todd Fialacacde7d2014-09-27 16:54:22 +000050#else
Kate Stoneb9c1b512016-09-06 20:57:50 +000051 error.SetErrorString("HostThreadPosix::Cancel() not supported on Android");
Todd Fialacacde7d2014-09-27 16:54:22 +000052#endif
Kate Stoneb9c1b512016-09-06 20:57:50 +000053 }
54 return error;
Zachary Turner39de3112014-09-09 20:54:56 +000055}
56
Kate Stoneb9c1b512016-09-06 20:57:50 +000057Error HostThreadPosix::Detach() {
58 Error error;
59 if (IsJoinable()) {
60 int err = ::pthread_detach(m_thread);
61 error.SetError(err, eErrorTypePOSIX);
62 }
63 Reset();
64 return error;
Zachary Turner39de3112014-09-09 20:54:56 +000065}