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