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 liblldb_ProcessRunLock_h_
10 #define liblldb_ProcessRunLock_h_
11 
12 #include <stdint.h>
13 #include <time.h>
14 
15 #include "lldb/lldb-defines.h"
16 
17 /// Enumerations for broadcasting.
18 namespace 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 
26 public:
29 
30  bool ReadTryLock();
31  bool ReadUnlock();
32  bool SetRunning();
33  bool TrySetRunning();
34  bool SetStopped();
35 
37  public:
38  ProcessRunLocker() : m_lock(nullptr) {}
39 
41 
42  // Try to lock the read lock, but only do so if there are no writers.
43  bool TryLock(ProcessRunLock *lock) {
44  if (m_lock) {
45  if (m_lock == lock)
46  return true; // We already have this lock locked
47  else
48  Unlock();
49  }
50  if (lock) {
51  if (lock->ReadTryLock()) {
52  m_lock = lock;
53  return true;
54  }
55  }
56  return false;
57  }
58 
59  protected:
60  void Unlock() {
61  if (m_lock) {
62  m_lock->ReadUnlock();
63  m_lock = nullptr;
64  }
65  }
66 
68 
69  private:
70  DISALLOW_COPY_AND_ASSIGN(ProcessRunLocker);
71  };
72 
73 protected:
75  bool m_running;
76 
77 private:
78  DISALLOW_COPY_AND_ASSIGN(ProcessRunLock);
79 };
80 
81 } // namespace lldb_private
82 
83 #endif // liblldb_ProcessRunLock_h_
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
A class used to prevent the process from starting while other threads are accessing its data...
pthread_rwlock_t rwlock_t
Definition: lldb-types.h:56