brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 8e7ef45 Raw
57 lines · cpp
1//===-- ProcessRunLock.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#ifndef _WIN3210#include "lldb/Host/ProcessRunLock.h"11 12namespace lldb_private {13 14ProcessRunLock::ProcessRunLock() {15  int err = ::pthread_rwlock_init(&m_rwlock, nullptr);16  (void)err;17}18 19ProcessRunLock::~ProcessRunLock() {20  int err = ::pthread_rwlock_destroy(&m_rwlock);21  (void)err;22}23 24bool ProcessRunLock::ReadTryLock() {25  ::pthread_rwlock_rdlock(&m_rwlock);26  if (!m_running) {27    // coverity[missing_unlock]28    return true;29  }30  ::pthread_rwlock_unlock(&m_rwlock);31  return false;32}33 34bool ProcessRunLock::ReadUnlock() {35  return ::pthread_rwlock_unlock(&m_rwlock) == 0;36}37 38bool ProcessRunLock::SetRunning() {39  ::pthread_rwlock_wrlock(&m_rwlock);40  bool was_stopped = !m_running;41  m_running = true;42  ::pthread_rwlock_unlock(&m_rwlock);43  return was_stopped;44}45 46bool ProcessRunLock::SetStopped() {47  ::pthread_rwlock_wrlock(&m_rwlock);48  bool was_running = m_running;49  m_running = false;50  ::pthread_rwlock_unlock(&m_rwlock);51  return was_running;52}53 54} // namespace lldb_private55 56#endif57