LLDB  mainline
windows/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 
11 
12 static PSRWLOCK GetLock(lldb::rwlock_t lock) {
13  return static_cast<PSRWLOCK>(lock);
14 }
15 
16 static bool ReadLock(lldb::rwlock_t rwlock) {
17  ::AcquireSRWLockShared(GetLock(rwlock));
18  return true;
19 }
20 
21 static bool ReadUnlock(lldb::rwlock_t rwlock) {
22  ::ReleaseSRWLockShared(GetLock(rwlock));
23  return true;
24 }
25 
26 static bool WriteLock(lldb::rwlock_t rwlock) {
27  ::AcquireSRWLockExclusive(GetLock(rwlock));
28  return true;
29 }
30 
31 static bool WriteTryLock(lldb::rwlock_t rwlock) {
32  return !!::TryAcquireSRWLockExclusive(GetLock(rwlock));
33 }
34 
35 static bool WriteUnlock(lldb::rwlock_t rwlock) {
36  ::ReleaseSRWLockExclusive(GetLock(rwlock));
37  return true;
38 }
39 
40 using namespace lldb_private;
41 
42 ProcessRunLock::ProcessRunLock() : m_running(false) {
43  m_rwlock = new SRWLOCK;
44  InitializeSRWLock(GetLock(m_rwlock));
45 }
46 
47 ProcessRunLock::~ProcessRunLock() { delete static_cast<SRWLOCK *>(m_rwlock); }
48 
51  if (m_running == false)
52  return true;
54  return false;
55 }
56 
58 
61  m_running = true;
63  return true;
64 }
65 
67  if (WriteTryLock(m_rwlock)) {
68  bool was_running = m_running;
69  m_running = true;
71  return !was_running;
72  }
73  return false;
74 }
75 
78  m_running = false;
80  return true;
81 }
lldb_private::ProcessRunLock::m_rwlock
lldb::rwlock_t m_rwlock
Definition: ProcessRunLock.h:75
WriteTryLock
static bool WriteTryLock(lldb::rwlock_t rwlock)
Definition: windows/ProcessRunLock.cpp:31
GetLock
static PSRWLOCK GetLock(lldb::rwlock_t lock)
Definition: windows/ProcessRunLock.cpp:12
ProcessRunLock.h
WriteLock
static bool WriteLock(lldb::rwlock_t rwlock)
Definition: windows/ProcessRunLock.cpp:26
WriteUnlock
static bool WriteUnlock(lldb::rwlock_t rwlock)
Definition: windows/ProcessRunLock.cpp:35
lldb_private::ProcessRunLock::ReadUnlock
bool ReadUnlock()
Definition: common/ProcessRunLock.cpp:33
lldb_private::ProcessRunLock::SetRunning
bool SetRunning()
Definition: common/ProcessRunLock.cpp:37
ReadLock
static bool ReadLock(lldb::rwlock_t rwlock)
Definition: windows/ProcessRunLock.cpp:16
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
ReadUnlock
static bool ReadUnlock(lldb::rwlock_t rwlock)
Definition: windows/ProcessRunLock.cpp:21
windows.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::rwlock_t
pthread_rwlock_t rwlock_t
Definition: lldb-types.h:56
lldb_private::ProcessRunLock::TrySetRunning
bool TrySetRunning()
Definition: common/ProcessRunLock.cpp:44
lldb_private::ProcessRunLock::ProcessRunLock
ProcessRunLock()
Definition: common/ProcessRunLock.cpp:14