rippled
Loading...
Searching...
No Matches
CountedObject.cpp
1#include <xrpl/basics/CountedObject.h>
2
3#include <algorithm>
4
5namespace ripple {
6
7CountedObjects&
9{
10 static CountedObjects instance;
11
12 return instance;
13}
14
15CountedObjects::CountedObjects() noexcept : m_count(0), m_head(nullptr)
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(m_count.load());
27
28 for (auto* ctr = m_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::sort(counts.begin(), counts.end());
35
36 return counts;
37}
38
39} // namespace ripple
T begin(T... args)
Manages all counted object types.
std::atomic< Counter * > m_head
std::atomic< int > m_count
static CountedObjects & getInstance() noexcept
List getCounts(int minimumThreshold) const
T emplace_back(T... args)
T end(T... args)
T load(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
T reserve(T... args)
T sort(T... args)