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_
12 #if defined(__cplusplus)
14 #include "lldb/Host/Mutex.h"
15 #include "lldb/Host/Condition.h"
20 //----------------------------------------------------------------------
21 /// Enumerations for broadcasting.
22 //----------------------------------------------------------------------
23 namespace lldb_private {
25 //----------------------------------------------------------------------
26 /// @class ProcessRunLock ProcessRunLock.h "lldb/Host/ProcessRunLock.h"
27 /// @brief A class used to prevent the process from starting while other
28 /// threads are accessing its data, and prevent access to its data while
30 //----------------------------------------------------------------------
39 int err = ::pthread_rwlock_init(&m_rwlock, NULL); (void)err;
40 //#if LLDB_CONFIGURATION_DEBUG
47 int err = ::pthread_rwlock_destroy (&m_rwlock); (void)err;
48 //#if LLDB_CONFIGURATION_DEBUG
56 ::pthread_rwlock_rdlock (&m_rwlock);
57 if (m_running == false)
61 ::pthread_rwlock_unlock (&m_rwlock);
68 return ::pthread_rwlock_unlock (&m_rwlock) == 0;
74 ::pthread_rwlock_wrlock (&m_rwlock);
76 ::pthread_rwlock_unlock (&m_rwlock);
85 if (::pthread_rwlock_trywrlock (&m_rwlock) == 0)
89 ::pthread_rwlock_unlock (&m_rwlock);
98 ::pthread_rwlock_wrlock (&m_rwlock);
100 ::pthread_rwlock_unlock (&m_rwlock);
104 class ProcessRunLocker
107 ProcessRunLocker () :
117 // Try to lock the read lock, but only do so if there are no writers.
119 TryLock (ProcessRunLock *lock)
124 return true; // We already have this lock locked
130 if (lock->ReadTryLock())
145 m_lock->ReadUnlock();
150 ProcessRunLock *m_lock;
152 DISALLOW_COPY_AND_ASSIGN(ProcessRunLocker);
156 pthread_rwlock_t m_rwlock;
159 DISALLOW_COPY_AND_ASSIGN(ProcessRunLock);
162 } // namespace lldb_private
164 #endif // #if defined(__cplusplus)
165 #endif // #ifndef liblldb_ProcessRunLock_h_