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

source code of lldb/source/Host/common/ProcessRunLock.cpp