Skip to content

Commit fa770ce

Browse files
author
MarcoFalke
committed
validationinterface: Rework documentation, Rename pwalletIn to callbacks
1 parent fab6d06 commit fa770ce

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

src/validationinterface.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,26 @@ struct MainSignalsInstance {
8989

9090
static CMainSignals g_signals;
9191

92-
void CMainSignals::RegisterBackgroundSignalScheduler(CScheduler& scheduler) {
92+
void CMainSignals::RegisterBackgroundSignalScheduler(CScheduler& scheduler)
93+
{
9394
assert(!m_internals);
9495
m_internals.reset(new MainSignalsInstance(&scheduler));
9596
}
9697

97-
void CMainSignals::UnregisterBackgroundSignalScheduler() {
98+
void CMainSignals::UnregisterBackgroundSignalScheduler()
99+
{
98100
m_internals.reset(nullptr);
99101
}
100102

101-
void CMainSignals::FlushBackgroundCallbacks() {
103+
void CMainSignals::FlushBackgroundCallbacks()
104+
{
102105
if (m_internals) {
103106
m_internals->m_schedulerClient.EmptyQueue();
104107
}
105108
}
106109

107-
size_t CMainSignals::CallbacksPending() {
110+
size_t CMainSignals::CallbacksPending()
111+
{
108112
if (!m_internals) return 0;
109113
return m_internals->m_schedulerClient.CallbacksPending();
110114
}
@@ -114,10 +118,11 @@ CMainSignals& GetMainSignals()
114118
return g_signals;
115119
}
116120

117-
void RegisterSharedValidationInterface(std::shared_ptr<CValidationInterface> pwalletIn) {
118-
// Each connection captures pwalletIn to ensure that each callback is
119-
// executed before pwalletIn is destroyed. For more details see #18338.
120-
g_signals.m_internals->Register(std::move(pwalletIn));
121+
void RegisterSharedValidationInterface(std::shared_ptr<CValidationInterface> callbacks)
122+
{
123+
// Each connection captures the shared_ptr to ensure that each callback is
124+
// executed before the subscriber is destroyed. For more details see #18338.
125+
g_signals.m_internals->Register(std::move(callbacks));
121126
}
122127

123128
void RegisterValidationInterface(CValidationInterface* callbacks)
@@ -132,24 +137,28 @@ void UnregisterSharedValidationInterface(std::shared_ptr<CValidationInterface> c
132137
UnregisterValidationInterface(callbacks.get());
133138
}
134139

135-
void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
140+
void UnregisterValidationInterface(CValidationInterface* callbacks)
141+
{
136142
if (g_signals.m_internals) {
137-
g_signals.m_internals->Unregister(pwalletIn);
143+
g_signals.m_internals->Unregister(callbacks);
138144
}
139145
}
140146

141-
void UnregisterAllValidationInterfaces() {
147+
void UnregisterAllValidationInterfaces()
148+
{
142149
if (!g_signals.m_internals) {
143150
return;
144151
}
145152
g_signals.m_internals->Clear();
146153
}
147154

148-
void CallFunctionInValidationInterfaceQueue(std::function<void ()> func) {
155+
void CallFunctionInValidationInterfaceQueue(std::function<void()> func)
156+
{
149157
g_signals.m_internals->m_schedulerClient.AddToProcessQueue(std::move(func));
150158
}
151159

152-
void SyncWithValidationInterfaceQueue() {
160+
void SyncWithValidationInterfaceQueue()
161+
{
153162
AssertLockNotHeld(cs_main);
154163
// Block until the validation queue drains
155164
std::promise<void> promise;

src/validationinterface.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ class CValidationInterface;
2222
class uint256;
2323
class CScheduler;
2424

25-
// These functions dispatch to one or all registered wallets
26-
27-
/** Register a wallet to receive updates from core */
28-
void RegisterValidationInterface(CValidationInterface* pwalletIn);
29-
/** Unregister a wallet from core */
30-
void UnregisterValidationInterface(CValidationInterface* pwalletIn);
31-
/** Unregister all wallets from core */
25+
/** Register subscriber */
26+
void RegisterValidationInterface(CValidationInterface* callbacks);
27+
/** Unregister subscriber. DEPRECATED. This is not safe to use when the RPC server or main message handler thread is running. */
28+
void UnregisterValidationInterface(CValidationInterface* callbacks);
29+
/** Unregister all subscribers */
3230
void UnregisterAllValidationInterfaces();
3331

3432
// Alternate registration functions that release a shared_ptr after the last
3533
// notification is sent. These are useful for race-free cleanup, since
3634
// unregistration is nonblocking and can return before the last notification is
3735
// processed.
36+
/** Register subscriber */
3837
void RegisterSharedValidationInterface(std::shared_ptr<CValidationInterface> callbacks);
38+
/** Unregister subscriber */
3939
void UnregisterSharedValidationInterface(std::shared_ptr<CValidationInterface> callbacks);
4040

4141
/**

0 commit comments

Comments
 (0)