Coverage Report

Created: 2023-09-21 18:56

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Host/common/ProcessRunLock.cpp
Line
Count
Source (jump to first uncovered line)
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
12
namespace lldb_private {
13
14
5.34k
ProcessRunLock::ProcessRunLock() {
15
5.34k
  int err = ::pthread_rwlock_init(&m_rwlock, nullptr);
16
5.34k
  (void)err;
17
5.34k
}
18
19
5.12k
ProcessRunLock::~ProcessRunLock() {
20
5.12k
  int err = ::pthread_rwlock_destroy(&m_rwlock);
21
5.12k
  (void)err;
22
5.12k
}
23
24
334k
bool ProcessRunLock::ReadTryLock() {
25
334k
  ::pthread_rwlock_rdlock(&m_rwlock);
26
334k
  if (!m_running) {
27
    // coverity[missing_unlock]
28
334k
    return true;
29
334k
  }
30
34
  ::pthread_rwlock_unlock(&m_rwlock);
31
34
  return false;
32
334k
}
33
34
334k
bool ProcessRunLock::ReadUnlock() {
35
334k
  return ::pthread_rwlock_unlock(&m_rwlock) == 0;
36
334k
}
37
38
13.8k
bool ProcessRunLock::SetRunning() {
39
13.8k
  ::pthread_rwlock_wrlock(&m_rwlock);
40
13.8k
  m_running = true;
41
13.8k
  ::pthread_rwlock_unlock(&m_rwlock);
42
13.8k
  return true;
43
13.8k
}
44
45
11.6k
bool ProcessRunLock::TrySetRunning() {
46
11.6k
  bool r;
47
48
11.6k
  if (::pthread_rwlock_trywrlock(&m_rwlock) == 0) {
49
11.6k
    r = !m_running;
50
11.6k
    m_running = true;
51
11.6k
    ::pthread_rwlock_unlock(&m_rwlock);
52
11.6k
    return r;
53
11.6k
  }
54
0
  return false;
55
11.6k
}
56
57
39.4k
bool ProcessRunLock::SetStopped() {
58
39.4k
  ::pthread_rwlock_wrlock(&m_rwlock);
59
39.4k
  m_running = false;
60
39.4k
  ::pthread_rwlock_unlock(&m_rwlock);
61
39.4k
  return true;
62
39.4k
}
63
}
64
65
#endif