62 lines · cpp
1//===-- HostThreadPosix.cpp -----------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "lldb/Host/posix/HostThreadPosix.h"10#include "lldb/Utility/Status.h"11 12#include <cerrno>13#include <pthread.h>14 15using namespace lldb;16using namespace lldb_private;17 18HostThreadPosix::HostThreadPosix() = default;19 20HostThreadPosix::HostThreadPosix(lldb::thread_t thread)21 : HostNativeThreadBase(thread) {}22 23HostThreadPosix::~HostThreadPosix() = default;24 25Status HostThreadPosix::Join(lldb::thread_result_t *result) {26 Status error;27 if (IsJoinable()) {28 int err = ::pthread_join(m_thread, result);29 error = Status(err, lldb::eErrorTypePOSIX);30 } else {31 if (result)32 *result = nullptr;33 error = Status(EINVAL, eErrorTypePOSIX);34 }35 36 Reset();37 return error;38}39 40Status HostThreadPosix::Cancel() {41 Status error;42 if (IsJoinable()) {43#ifndef __FreeBSD__44 llvm_unreachable("someone is calling HostThread::Cancel()");45#else46 int err = ::pthread_cancel(m_thread);47 error = Status(err, eErrorTypePOSIX);48#endif49 }50 return error;51}52 53Status HostThreadPosix::Detach() {54 Status error;55 if (IsJoinable()) {56 int err = ::pthread_detach(m_thread);57 error = Status(err, eErrorTypePOSIX);58 }59 Reset();60 return error;61}62