rippled
Loading...
Searching...
No Matches
PendingSaves.h
1#pragma once
2
3#include <xrpl/protocol/Protocol.h>
4
5#include <condition_variable>
6#include <map>
7#include <mutex>
8
9namespace xrpl {
10
18{
19private:
23
24public:
31 bool
33 {
35
36 auto it = map_.find(seq);
37
38 if ((it == map_.end()) || it->second)
39 {
40 // Work done or another thread is doing it
41 return false;
42 }
43
44 it->second = true;
45 return true;
46 }
47
54 void
56 {
58
59 map_.erase(seq);
61 }
62
64 bool
66 {
68 return map_.find(seq) != map_.end();
69 }
70
79 bool
80 shouldWork(LedgerIndex seq, bool isSynchronous)
81 {
83 do
84 {
85 auto it = map_.find(seq);
86
87 if (it == map_.end())
88 {
89 map_.emplace(seq, false);
90 return true;
91 }
92
93 if (!isSynchronous)
94 {
95 // Already dispatched
96 return false;
97 }
98
99 if (!it->second)
100 {
101 // Scheduled, but not dispatched
102 return true;
103 }
104
105 // Already in progress, just need to wait
106 await_.wait(lock);
107
108 } while (true);
109 }
110
119 {
121
122 return map_;
123 }
124};
125
126} // namespace xrpl
Keeps track of which ledgers haven't been fully saved.
std::condition_variable await_
std::map< LedgerIndex, bool > getSnapshot() const
Get a snapshot of the pending saves.
void finishWork(LedgerIndex seq)
Finish working on a ledger.
bool shouldWork(LedgerIndex seq, bool isSynchronous)
Check if a ledger should be dispatched.
bool startWork(LedgerIndex seq)
Start working on a ledger.
bool pending(LedgerIndex seq)
Return true if a ledger is in the progress of being saved.
std::map< LedgerIndex, bool > map_
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5