xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
basics
CountedObject.cpp
1
#include <xrpl/basics/CountedObject.h>
2
3
#include <
algorithm
>
4
5
namespace
xrpl
{
6
7
CountedObjects
&
8
CountedObjects::getInstance
() noexcept
9
{
10
static
CountedObjects
kInstance;
11
12
return
kInstance;
13
}
14
15
CountedObjects::CountedObjects
() noexcept :
count_
(0),
head_
(
nullptr
)
16
{
17
}
18
19
CountedObjects::List
20
CountedObjects::getCounts
(
int
minimumThreshold)
const
21
{
22
List
counts;
23
24
// When other operations are concurrent, the count
25
// might be temporarily less than the actual count.
26
counts.
reserve
(
count_
.load());
27
28
for
(
auto
* ctr =
head_
.load(); ctr !=
nullptr
; ctr = ctr->getNext())
29
{
30
if
(ctr->getCount() >= minimumThreshold)
31
counts.
emplace_back
(ctr->getName(), ctr->getCount());
32
}
33
34
std::ranges::sort
(counts);
35
36
return
counts;
37
}
38
39
}
// namespace xrpl
algorithm
xrpl::CountedObjects
Manages all counted object types.
Definition
CountedObject.h:16
xrpl::CountedObjects::getCounts
List getCounts(int minimumThreshold) const
Definition
CountedObject.cpp:20
xrpl::CountedObjects::getInstance
static CountedObjects & getInstance() noexcept
Definition
CountedObject.cpp:8
xrpl::CountedObjects::List
std::vector< Entry > List
Definition
CountedObject.h:22
xrpl::CountedObjects::head_
std::atomic< Counter * > head_
Definition
CountedObject.h:95
xrpl::CountedObjects::count_
std::atomic< int > count_
Definition
CountedObject.h:94
xrpl::CountedObjects::CountedObjects
CountedObjects() noexcept
Definition
CountedObject.cpp:15
std::vector::emplace_back
T emplace_back(T... args)
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
std::vector::reserve
T reserve(T... args)
std::ranges::sort
T sort(T... args)
Generated by
1.17.0