LLDB
mainline
llvm-project
lldb
include
lldb
Host
ProcessRunLock.h
Go to the documentation of this file.
1
//===-- ProcessRunLock.h ----------------------------------------*- C++ -*-===//
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 LLDB_HOST_PROCESSRUNLOCK_H
10
#define LLDB_HOST_PROCESSRUNLOCK_H
11
12
#include <cstdint>
13
#include <ctime>
14
15
#include "
lldb/lldb-defines.h
"
16
17
/// Enumerations for broadcasting.
18
namespace
lldb_private
{
19
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
23
/// running.
24
25
class
ProcessRunLock
{
26
public
:
27
ProcessRunLock
();
28
~ProcessRunLock
();
29
30
bool
ReadTryLock
();
31
bool
ReadUnlock
();
32
bool
SetRunning
();
33
bool
TrySetRunning
();
34
bool
SetStopped
();
35
36
class
ProcessRunLocker
{
37
public
:
38
ProcessRunLocker
() =
default
;
39
40
~ProcessRunLocker
() {
Unlock
(); }
41
42
// Try to lock the read lock, but only do so if there are no writers.
43
bool
TryLock
(
ProcessRunLock
*lock) {
44
if
(
m_lock
) {
45
if
(
m_lock
== lock)
46
return
true
;
// We already have this lock locked
47
else
48
Unlock
();
49
}
50
if
(lock) {
51
if
(lock->
ReadTryLock
()) {
52
m_lock
= lock;
53
return
true
;
54
}
55
}
56
return
false
;
57
}
58
59
protected
:
60
void
Unlock
() {
61
if
(
m_lock
) {
62
m_lock
->
ReadUnlock
();
63
m_lock
=
nullptr
;
64
}
65
}
66
67
ProcessRunLock
*
m_lock
=
nullptr
;
68
69
private
:
70
ProcessRunLocker
(
const
ProcessRunLocker
&) =
delete
;
71
const
ProcessRunLocker
&
operator=
(
const
ProcessRunLocker
&) =
delete
;
72
};
73
74
protected
:
75
lldb::rwlock_t
m_rwlock
;
76
bool
m_running
=
false
;
77
78
private
:
79
ProcessRunLock
(
const
ProcessRunLock
&) =
delete
;
80
const
ProcessRunLock
&
operator=
(
const
ProcessRunLock
&) =
delete
;
81
};
82
83
}
// namespace lldb_private
84
85
#endif // LLDB_HOST_PROCESSRUNLOCK_H
lldb_private::ProcessRunLock::m_rwlock
lldb::rwlock_t m_rwlock
Definition:
ProcessRunLock.h:75
lldb-defines.h
lldb_private::ProcessRunLock::operator=
const ProcessRunLock & operator=(const ProcessRunLock &)=delete
lldb_private::ProcessRunLock::ProcessRunLocker
Definition:
ProcessRunLock.h:36
lldb_private::ProcessRunLock::ProcessRunLocker::~ProcessRunLocker
~ProcessRunLocker()
Definition:
ProcessRunLock.h:40
lldb_private::ProcessRunLock::ProcessRunLocker::ProcessRunLocker
ProcessRunLocker()=default
lldb_private::ProcessRunLock::ProcessRunLocker::Unlock
void Unlock()
Definition:
ProcessRunLock.h:60
lldb_private::ProcessRunLock::~ProcessRunLock
~ProcessRunLock()
Definition:
common/ProcessRunLock.cpp:19
lldb_private::ProcessRunLock
Definition:
ProcessRunLock.h:25
lldb_private::ProcessRunLock::ProcessRunLocker::m_lock
ProcessRunLock * m_lock
Definition:
ProcessRunLock.h:67
lldb_private::ProcessRunLock::ReadUnlock
bool ReadUnlock()
Definition:
common/ProcessRunLock.cpp:33
lldb_private::ProcessRunLock::ProcessRunLocker::TryLock
bool TryLock(ProcessRunLock *lock)
Definition:
ProcessRunLock.h:43
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::ProcessRunLocker::operator=
const ProcessRunLocker & operator=(const ProcessRunLocker &)=delete
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::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
Generated on Wed Jul 6 2022 08:25:07 for LLDB by
1.8.17