blob: 0f4434d25e2ebb5494da89be958bbd0700283a44 [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 Turner97206d52017-05-12 04:51:55 +000011#include "lldb/Utility/Status.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
Zachary Turner97206d52017-05-12 04:51:55 +000026Status HostThreadPosix::Join(lldb::thread_result_t *result) {
27 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +000028 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
Zachary Turner97206d52017-05-12 04:51:55 +000041Status HostThreadPosix::Cancel() {
42 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +000043 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
Zachary Turner97206d52017-05-12 04:51:55 +000057Status HostThreadPosix::Detach() {
58 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +000059 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}