Clio
develop
The XRP Ledger API server.
Theme:
Default
Round
Robot
Toggle main menu visibility
Loading...
Searching...
No Matches
Mutex.hpp
1
#pragma once
2
3
#include <mutex>
4
#include <type_traits>
5
6
namespace
util
{
7
8
template
<
typename
ProtectedDataType,
typename
MutextType>
9
class
Mutex
;
10
18
template
<
typename
ProtectedDataType,
template
<
typename
...>
typename
LockType,
typename
MutexType>
19
class
Lock {
20
LockType<MutexType> lock_;
21
ProtectedDataType& data_;
22
23
public
:
25
ProtectedDataType
const
&
26
operator*()
const
27
{
28
return
data_;
29
}
30
31
ProtectedDataType&
32
operator*()
33
{
34
return
data_;
35
}
36
37
[[nodiscard]] ProtectedDataType
const
&
38
get()
const
39
{
40
return
data_;
41
}
42
43
ProtectedDataType&
44
get()
45
{
46
return
data_;
47
}
48
49
ProtectedDataType
const
*
50
operator->()
const
51
{
52
return
&data_;
53
}
54
55
ProtectedDataType*
56
operator->()
57
{
58
return
&data_;
59
}
60
61
operator
LockType<MutexType>&()
62
{
63
return
lock_;
64
}
66
67
private
:
68
friend
class
Mutex
<std::remove_const_t<ProtectedDataType>, MutexType>;
69
70
Lock(MutexType& mutex, ProtectedDataType& data) : lock_(mutex), data_(data)
71
{
72
}
73
};
74
81
template
<
typename
ProtectedDataType,
typename
MutexType = std::mutex>
82
class
Mutex {
83
mutable
MutexType mutex_;
84
ProtectedDataType data_;
85
86
public
:
87
Mutex() =
default
;
88
94
explicit
Mutex
(ProtectedDataType
data
) : data_(std::move(
data
))
95
{
96
}
97
105
template
<
typename
... Args>
106
static
Mutex
107
make
(Args&&... args)
108
{
109
return
Mutex{ProtectedDataType{std::forward<Args>(args)...}};
110
}
111
118
template
<
template
<
typename
...>
typename
LockType = std::lock_guard>
119
Lock<ProtectedDataType const, LockType, MutexType>
120
lock
()
const
121
{
122
return
{mutex_, data_};
123
}
124
131
template
<
template
<
typename
...>
typename
LockType = std::lock_guard>
132
Lock<ProtectedDataType, LockType, MutexType>
133
lock
()
134
{
135
return
{mutex_, data_};
136
}
137
};
138
139
}
// namespace util
util::Lock
A lock on a mutex that provides access to the protected data.
Definition
Mutex.hpp:19
util::Mutex
A container for data that is protected by a mutex. Inspired by Mutex in Rust.
Definition
Mutex.hpp:82
util::Mutex::lock
Lock< ProtectedDataType, LockType, MutexType > lock()
Lock the mutex and get a lock object allowing access to the protected data.
Definition
Mutex.hpp:133
util::Mutex::make
static Mutex make(Args &&... args)
Make a new Mutex object with the given data.
Definition
Mutex.hpp:107
util::Mutex::Mutex
Mutex(ProtectedDataType data)
Construct a new Mutex object with the given data.
Definition
Mutex.hpp:94
util::Mutex::lock
Lock< ProtectedDataType const, LockType, MutexType > lock() const
Lock the mutex and get a lock object allowing access to the protected data.
Definition
Mutex.hpp:120
data
This namespace implements the data access layer and related components.
Definition
AmendmentCenter.cpp:56
util
This namespace contains various utilities.
Definition
HandlerRegistry.hpp:24
src
util
Mutex.hpp
Generated by
1.17.0