LLDB  mainline
common/ProcessRunLock.cpp
Go to the documentation of this file.
1 //===-- ProcessRunLock.cpp ------------------------------------------------===//
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 _WIN32
11 
12 namespace lldb_private {
13 
15  int err = ::pthread_rwlock_init(&m_rwlock, nullptr);
16  (void)err;
17 }
18 
20  int err = ::pthread_rwlock_destroy(&m_rwlock);
21  (void)err;
22 }
23 
25  ::pthread_rwlock_rdlock(&m_rwlock);
26  if (!m_running) {
27  return true;
28  }
29  ::pthread_rwlock_unlock(&m_rwlock);
30  return false;
31 }
32 
34  return ::pthread_rwlock_unlock(&m_rwlock) == 0;
35 }
36 
38  ::pthread_rwlock_wrlock(&m_rwlock);
39  m_running = true;
40  ::pthread_rwlock_unlock(&m_rwlock);
41  return true;
42 }
43 
45  bool r;
46 
47  if (::pthread_rwlock_trywrlock(&m_rwlock) == 0) {
48  r = !m_running;
49  m_running = true;
50  ::pthread_rwlock_unlock(&m_rwlock);
51  return r;
52  }
53  return false;
54 }
55 
57  ::pthread_rwlock_wrlock(&m_rwlock);
58  m_running = false;
59  ::pthread_rwlock_unlock(&m_rwlock);
60  return true;
61 }
62 }
63 
64 #endif
lldb_private::ProcessRunLock::m_rwlock
lldb::rwlock_t m_rwlock
Definition: ProcessRunLock.h:75
ProcessRunLock.h
lldb_private::ProcessRunLock::~ProcessRunLock
~ProcessRunLock()
Definition: common/ProcessRunLock.cpp:19
lldb_private::ProcessRunLock::ReadUnlock
bool ReadUnlock()
Definition: common/ProcessRunLock.cpp:33
lldb_private::ProcessRunLock::SetRunning
bool SetRunning()
Definition: common/ProcessRunLock.cpp:37
lldb_private::ProcessRunLock::SetStopped
bool SetStopped()
Definition: common/ProcessRunLock.cpp:56
lldb_private::ProcessRunLock::m_running
bool m_running
Definition: ProcessRunLock.h:76
lldb_private::ProcessRunLock::ReadTryLock
bool ReadTryLock()
Definition: common/ProcessRunLock.cpp:24
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ProcessRunLock::TrySetRunning
bool TrySetRunning()
Definition: common/ProcessRunLock.cpp:44
lldb_private::ProcessRunLock::ProcessRunLock
ProcessRunLock()
Definition: common/ProcessRunLock.cpp:14