1 //===-- ProcessRunLock.h ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ProcessRunLock_h_
11 #define liblldb_ProcessRunLock_h_
16 #include "lldb/lldb-defines.h"
18 //----------------------------------------------------------------------
19 /// Enumerations for broadcasting.
20 //----------------------------------------------------------------------
21 namespace lldb_private {
23 //----------------------------------------------------------------------
24 /// @class ProcessRunLock ProcessRunLock.h "lldb/Host/ProcessRunLock.h"
25 /// A class used to prevent the process from starting while other
26 /// threads are accessing its data, and prevent access to its data while it is
28 //----------------------------------------------------------------------
30 class ProcessRunLock {
41 class ProcessRunLocker {
43 ProcessRunLocker() : m_lock(nullptr) {}
45 ~ProcessRunLocker() { Unlock(); }
47 // Try to lock the read lock, but only do so if there are no writers.
48 bool TryLock(ProcessRunLock *lock) {
51 return true; // We already have this lock locked
56 if (lock->ReadTryLock()) {
72 ProcessRunLock *m_lock;
75 DISALLOW_COPY_AND_ASSIGN(ProcessRunLocker);
79 lldb::rwlock_t m_rwlock;
83 DISALLOW_COPY_AND_ASSIGN(ProcessRunLock);
86 } // namespace lldb_private
88 #endif // liblldb_ProcessRunLock_h_