xrpld
Loading...
Searching...
No Matches
CountedObject.cpp
1#include <xrpl/basics/CountedObject.h>
2
3#include <algorithm>
4
5namespace xrpl {
6
9{
10 static CountedObjects kInstance;
11
12 return kInstance;
13}
14
16{
17}
18
20CountedObjects::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
Manages all counted object types.
List getCounts(int minimumThreshold) const
static CountedObjects & getInstance() noexcept
std::vector< Entry > List
std::atomic< Counter * > head_
std::atomic< int > count_
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
T reserve(T... args)
T sort(T... args)