rippled
Loading...
Searching...
No Matches
LedgerHolder.h
1#pragma once
2
3#include <xrpl/basics/CountedObject.h>
4#include <xrpl/basics/contract.h>
5
6#include <mutex>
7
8namespace xrpl {
9
10// Can std::atomic<std::shared_ptr>> make this lock free?
11
12// VFALCO NOTE This class can be replaced with atomic<shared_ptr<...>>
13
20class LedgerHolder : public CountedObject<LedgerHolder>
21{
22public:
23 // Update the held ledger
24 void
26 {
27 if (!ledger)
28 LogicError("LedgerHolder::set with nullptr");
29 if (!ledger->isImmutable())
30 LogicError("LedgerHolder::set with mutable Ledger");
32 m_heldLedger = std::move(ledger);
33 }
34
35 // Return the (immutable) held ledger
38 {
40 return m_heldLedger;
41 }
42
43 bool
45 {
47 return m_heldLedger == nullptr;
48 }
49
50private:
53};
54
55} // namespace xrpl
Tracks the number of instances of an object.
Hold a ledger in a thread-safe way.
void set(std::shared_ptr< Ledger const > ledger)
std::shared_ptr< Ledger const > get()
std::shared_ptr< Ledger const > m_heldLedger
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.