blob: 13de42f763ec700966f7fa71152cb29848cd6427 [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()) {
Ed Maste718e2962016-05-13 17:01:59 +000044#ifndef __FreeBSD__
Davide Italianoc12c0c52017-11-15 23:39:41 +000045 llvm_unreachable("someone is calling HostThread::Cancel()");
Pavel Labath408b0f52018-03-06 12:46:05 +000046#else
Kate Stoneb9c1b512016-09-06 20:57:50 +000047 int err = ::pthread_cancel(m_thread);
48 error.SetError(err, eErrorTypePOSIX);
Todd Fialacacde7d2014-09-27 16:54:22 +000049#endif
Kate Stoneb9c1b512016-09-06 20:57:50 +000050 }
51 return error;
Zachary Turner39de3112014-09-09 20:54:56 +000052}
53
Zachary Turner97206d52017-05-12 04:51:55 +000054Status HostThreadPosix::Detach() {
55 Status error;
Kate Stoneb9c1b512016-09-06 20:57:50 +000056 if (IsJoinable()) {
57 int err = ::pthread_detach(m_thread);
58 error.SetError(err, eErrorTypePOSIX);
59 }
60 Reset();
61 return error;
Zachary Turner39de3112014-09-09 20:54:56 +000062}