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_
18 // Other libraries and framework includes
20 #include "lldb/lldb-defines.h"
22 //----------------------------------------------------------------------
23 /// Enumerations for broadcasting.
24 //----------------------------------------------------------------------
25 namespace lldb_private {
27 //----------------------------------------------------------------------
28 /// @class ProcessRunLock ProcessRunLock.h "lldb/Host/ProcessRunLock.h"
29 /// A class used to prevent the process from starting while other
30 /// threads are accessing its data, and prevent access to its data while it is
32 //----------------------------------------------------------------------
34 class ProcessRunLock {
45 class ProcessRunLocker {
47 ProcessRunLocker() : m_lock(nullptr) {}
49 ~ProcessRunLocker() { Unlock(); }
51 // Try to lock the read lock, but only do so if there are no writers.
52 bool TryLock(ProcessRunLock *lock) {
55 return true; // We already have this lock locked
60 if (lock->ReadTryLock()) {
76 ProcessRunLock *m_lock;
79 DISALLOW_COPY_AND_ASSIGN(ProcessRunLocker);
83 lldb::rwlock_t m_rwlock;
87 DISALLOW_COPY_AND_ASSIGN(ProcessRunLock);
90 } // namespace lldb_private
92 #endif // liblldb_ProcessRunLock_h_