blob: 6b1b88bb05d0c6f194e9cdbe674f6c110951a88d [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 {
Zachary Turneracee96a2014-09-23 18:32:09 +000038 lldb::thread_result_t thread_result;
39 int err = ::pthread_join(m_thread, &thread_result);
40 error.SetError(err, lldb::eErrorTypePOSIX);
Zachary Turner39de3112014-09-09 20:54:56 +000041 }
Zachary Turneracee96a2014-09-23 18:32:09 +000042 else
43 error.SetError(EINVAL, eErrorTypePOSIX);
44
45 Reset();
Zachary Turner39de3112014-09-09 20:54:56 +000046 return error;
47}
48
49Error
50HostThreadPosix::Cancel()
51{
52 Error error;
Todd Fialacacde7d2014-09-27 16:54:22 +000053#ifndef __ANDROID__
Zachary Turner39de3112014-09-09 20:54:56 +000054 int err = ::pthread_cancel(m_thread);
Zachary Turneracee96a2014-09-23 18:32:09 +000055 error.SetError(err, eErrorTypePOSIX);
Todd Fialacacde7d2014-09-27 16:54:22 +000056#else
57 error.SetErrorString("HostThreadPosix::Cancel() not supported on Android");
58#endif
Zachary Turner39de3112014-09-09 20:54:56 +000059
60 return error;
61}
62
63Error
64HostThreadPosix::Detach()
65{
66 Error error;
67 int err = ::pthread_detach(m_thread);
Zachary Turneracee96a2014-09-23 18:32:09 +000068 error.SetError(err, eErrorTypePOSIX);
69 Reset();
Zachary Turner39de3112014-09-09 20:54:56 +000070 return error;
71}