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