blob: 3ac83ac07b1e6ac0095d88d6bb375fc0ca8dc353 [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__
Greg Clayton1e20f022016-05-12 22:58:52 +000059 assert(false && "someone is calling HostThread::Cancel()");
60 int err = ::pthread_cancel(m_thread);
61 error.SetError(err, eErrorTypePOSIX);
Todd Fialacacde7d2014-09-27 16:54:22 +000062#else
Greg Clayton1e20f022016-05-12 22:58:52 +000063 error.SetErrorString("HostThreadPosix::Cancel() not supported on Android");
Todd Fialacacde7d2014-09-27 16:54:22 +000064#endif
Greg Clayton1e20f022016-05-12 22:58:52 +000065 }
Zachary Turner39de3112014-09-09 20:54:56 +000066 return error;
67}
68
69Error
70HostThreadPosix::Detach()
71{
72 Error error;
Greg Clayton1e20f022016-05-12 22:58:52 +000073 if (IsJoinable())
74 {
75 int err = ::pthread_detach(m_thread);
76 error.SetError(err, eErrorTypePOSIX);
77 }
Zachary Turneracee96a2014-09-23 18:32:09 +000078 Reset();
Zachary Turner39de3112014-09-09 20:54:56 +000079 return error;
80}