Path: blob/main/contrib/llvm-project/lldb/source/Host/common/ProcessRunLock.cpp
39606 views
//===-- ProcessRunLock.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#ifndef _WIN329#include "lldb/Host/ProcessRunLock.h"1011namespace lldb_private {1213ProcessRunLock::ProcessRunLock() {14int err = ::pthread_rwlock_init(&m_rwlock, nullptr);15(void)err;16}1718ProcessRunLock::~ProcessRunLock() {19int err = ::pthread_rwlock_destroy(&m_rwlock);20(void)err;21}2223bool ProcessRunLock::ReadTryLock() {24::pthread_rwlock_rdlock(&m_rwlock);25if (!m_running) {26// coverity[missing_unlock]27return true;28}29::pthread_rwlock_unlock(&m_rwlock);30return false;31}3233bool ProcessRunLock::ReadUnlock() {34return ::pthread_rwlock_unlock(&m_rwlock) == 0;35}3637bool ProcessRunLock::SetRunning() {38::pthread_rwlock_wrlock(&m_rwlock);39m_running = true;40::pthread_rwlock_unlock(&m_rwlock);41return true;42}4344bool ProcessRunLock::TrySetRunning() {45bool r;4647if (::pthread_rwlock_trywrlock(&m_rwlock) == 0) {48r = !m_running;49m_running = true;50::pthread_rwlock_unlock(&m_rwlock);51return r;52}53return false;54}5556bool ProcessRunLock::SetStopped() {57::pthread_rwlock_wrlock(&m_rwlock);58m_running = false;59::pthread_rwlock_unlock(&m_rwlock);60return true;61}62}6364#endif656667