1 //===-- ProcessRunLock.h ----------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_ProcessRunLock_h_
10 #define liblldb_ProcessRunLock_h_
15 #include "lldb/lldb-defines.h"
17 /// Enumerations for broadcasting.
18 namespace lldb_private {
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
25 class ProcessRunLock {
36 class ProcessRunLocker {
38 ProcessRunLocker() : m_lock(nullptr) {}
40 ~ProcessRunLocker() { Unlock(); }
42 // Try to lock the read lock, but only do so if there are no writers.
43 bool TryLock(ProcessRunLock *lock) {
46 return true; // We already have this lock locked
51 if (lock->ReadTryLock()) {
67 ProcessRunLock *m_lock;
70 DISALLOW_COPY_AND_ASSIGN(ProcessRunLocker);
74 lldb::rwlock_t m_rwlock;
78 DISALLOW_COPY_AND_ASSIGN(ProcessRunLock);
81 } // namespace lldb_private
83 #endif // liblldb_ProcessRunLock_h_