blob: f1a6d6f8314220913cbde5d455487127dd9cd7fa [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;
Greg Clayton1e20f022016-05-12 22:58:52 +000056 if (IsJoinable())
57 {
Todd Fialacacde7d2014-09-27 16:54:22 +000058#ifndef __ANDROID__
Ed Maste718e2962016-05-13 17:01:59 +000059#ifndef __FreeBSD__
Greg Clayton1e20f022016-05-12 22:58:52 +000060 assert(false && "someone is calling HostThread::Cancel()");
Ed Maste718e2962016-05-13 17:01:59 +000061#endif
Greg Clayton1e20f022016-05-12 22:58:52 +000062 int err = ::pthread_cancel(m_thread);
63 error.SetError(err, eErrorTypePOSIX);
Todd Fialacacde7d2014-09-27 16:54:22 +000064#else
Greg Clayton1e20f022016-05-12 22:58:52 +000065 error.SetErrorString("HostThreadPosix::Cancel() not supported on Android");
Todd Fialacacde7d2014-09-27 16:54:22 +000066#endif
Greg Clayton1e20f022016-05-12 22:58:52 +000067 }
Zachary Turner39de3112014-09-09 20:54:56 +000068 return error;
69}
70
71Error
72HostThreadPosix::Detach()
73{
74 Error error;
Greg Clayton1e20f022016-05-12 22:58:52 +000075 if (IsJoinable())
76 {
77 int err = ::pthread_detach(m_thread);
78 error.SetError(err, eErrorTypePOSIX);
79 }
Zachary Turneracee96a2014-09-23 18:32:09 +000080 Reset();
Zachary Turner39de3112014-09-09 20:54:56 +000081 return error;
82}