LLDB mainline
ProcessRunLock.h
Go to the documentation of this file.
1//===-- ProcessRunLock.h ----------------------------------------*- C++ -*-===//
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 LLDB_HOST_PROCESSRUNLOCK_H
10#define LLDB_HOST_PROCESSRUNLOCK_H
11
12#include <cstdint>
13#include <ctime>
14
15#include "lldb/lldb-defines.h"
16
17/// Enumerations for broadcasting.
18namespace lldb_private {
19
20/// \class ProcessRunLock ProcessRunLock.h "lldb/Host/ProcessRunLock.h"
21/// A class used to prevent the process from starting while other
22/// threads are accessing its data, and prevent access to its data while it is
23/// running.
24
26public:
29
30 bool ReadTryLock();
31 bool ReadUnlock();
32
33 /// Set the process to running. Returns true if the process was stopped.
34 /// Return false if the process was running.
35 bool SetRunning();
36
37 /// Set the process to stopped. Returns true if the process was running.
38 /// Returns false if the process was stopped.
39 bool SetStopped();
40
42 public:
43 ProcessRunLocker() = default;
45 other.m_lock = nullptr;
46 }
48 if (this != &other) {
49 Unlock();
50 m_lock = other.m_lock;
51 other.m_lock = nullptr;
52 }
53 return *this;
54 }
55
57
58 bool IsLocked() const { return m_lock; }
59
60 // Try to lock the read lock, but only do so if there are no writers.
61 bool TryLock(ProcessRunLock *lock) {
62 if (m_lock) {
63 if (m_lock == lock)
64 return true; // We already have this lock locked
65 else
66 Unlock();
67 }
68 if (lock) {
69 if (lock->ReadTryLock()) {
70 m_lock = lock;
71 return true;
72 }
73 }
74 return false;
75 }
76
77 protected:
78 void Unlock() {
79 if (m_lock) {
80 m_lock->ReadUnlock();
81 m_lock = nullptr;
82 }
83 }
84
86
87 private:
90 };
91
92protected:
94 bool m_running = false;
95
96private:
97 ProcessRunLock(const ProcessRunLock &) = delete;
98 const ProcessRunLock &operator=(const ProcessRunLock &) = delete;
99};
100
101} // namespace lldb_private
102
103#endif // LLDB_HOST_PROCESSRUNLOCK_H
ProcessRunLocker & operator=(ProcessRunLocker &&other)
ProcessRunLocker(const ProcessRunLocker &)=delete
const ProcessRunLocker & operator=(const ProcessRunLocker &)=delete
bool SetStopped()
Set the process to stopped.
ProcessRunLock(const ProcessRunLock &)=delete
bool SetRunning()
Set the process to running.
const ProcessRunLock & operator=(const ProcessRunLock &)=delete
A class that represents a running process on the host machine.
pthread_rwlock_t rwlock_t
Definition lldb-types.h:56