2014-09-10 04:54:56 +08:00
|
|
|
//===-- HostThreadPosix.cpp -------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Host/posix/HostThreadPosix.h"
|
2017-05-12 12:51:55 +08:00
|
|
|
#include "lldb/Utility/Status.h"
|
2014-09-10 04:54:56 +08:00
|
|
|
|
2014-09-24 02:32:09 +08:00
|
|
|
#include <errno.h>
|
2014-09-10 04:54:56 +08:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2014-09-24 02:32:09 +08:00
|
|
|
using namespace lldb;
|
2014-09-10 04:54:56 +08:00
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
HostThreadPosix::HostThreadPosix() {}
|
2014-09-10 04:54:56 +08:00
|
|
|
|
|
|
|
HostThreadPosix::HostThreadPosix(lldb::thread_t thread)
|
2016-09-07 04:57:50 +08:00
|
|
|
: HostNativeThreadBase(thread) {}
|
2014-09-10 04:54:56 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
HostThreadPosix::~HostThreadPosix() {}
|
2014-09-10 04:54:56 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status HostThreadPosix::Join(lldb::thread_result_t *result) {
|
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
if (IsJoinable()) {
|
|
|
|
int err = ::pthread_join(m_thread, result);
|
|
|
|
error.SetError(err, lldb::eErrorTypePOSIX);
|
|
|
|
} else {
|
|
|
|
if (result)
|
|
|
|
*result = NULL;
|
|
|
|
error.SetError(EINVAL, eErrorTypePOSIX);
|
|
|
|
}
|
2014-09-24 02:32:09 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Reset();
|
|
|
|
return error;
|
2014-09-10 04:54:56 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status HostThreadPosix::Cancel() {
|
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
if (IsJoinable()) {
|
2014-09-28 00:54:22 +08:00
|
|
|
#ifndef __ANDROID__
|
2016-05-14 01:01:59 +08:00
|
|
|
#ifndef __FreeBSD__
|
2017-11-16 07:39:41 +08:00
|
|
|
llvm_unreachable("someone is calling HostThread::Cancel()");
|
2016-05-14 01:01:59 +08:00
|
|
|
#endif
|
2016-09-07 04:57:50 +08:00
|
|
|
int err = ::pthread_cancel(m_thread);
|
|
|
|
error.SetError(err, eErrorTypePOSIX);
|
2014-09-28 00:54:22 +08:00
|
|
|
#else
|
2016-09-07 04:57:50 +08:00
|
|
|
error.SetErrorString("HostThreadPosix::Cancel() not supported on Android");
|
2014-09-28 00:54:22 +08:00
|
|
|
#endif
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return error;
|
2014-09-10 04:54:56 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status HostThreadPosix::Detach() {
|
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
if (IsJoinable()) {
|
|
|
|
int err = ::pthread_detach(m_thread);
|
|
|
|
error.SetError(err, eErrorTypePOSIX);
|
|
|
|
}
|
|
|
|
Reset();
|
|
|
|
return error;
|
2014-09-10 04:54:56 +08:00
|
|
|
}
|