Path: blob/main/contrib/llvm-project/lldb/source/Host/posix/HostThreadPosix.cpp
39607 views
//===-- HostThreadPosix.cpp -----------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Host/posix/HostThreadPosix.h"9#include "lldb/Utility/Status.h"1011#include <cerrno>12#include <pthread.h>1314using namespace lldb;15using namespace lldb_private;1617HostThreadPosix::HostThreadPosix() = default;1819HostThreadPosix::HostThreadPosix(lldb::thread_t thread)20: HostNativeThreadBase(thread) {}2122HostThreadPosix::~HostThreadPosix() = default;2324Status HostThreadPosix::Join(lldb::thread_result_t *result) {25Status error;26if (IsJoinable()) {27int err = ::pthread_join(m_thread, result);28error.SetError(err, lldb::eErrorTypePOSIX);29} else {30if (result)31*result = nullptr;32error.SetError(EINVAL, eErrorTypePOSIX);33}3435Reset();36return error;37}3839Status HostThreadPosix::Cancel() {40Status error;41if (IsJoinable()) {42#ifndef __FreeBSD__43llvm_unreachable("someone is calling HostThread::Cancel()");44#else45int err = ::pthread_cancel(m_thread);46error.SetError(err, eErrorTypePOSIX);47#endif48}49return error;50}5152Status HostThreadPosix::Detach() {53Status error;54if (IsJoinable()) {55int err = ::pthread_detach(m_thread);56error.SetError(err, eErrorTypePOSIX);57}58Reset();59return error;60}616263