Skip to content

Commit

Permalink
Merge #15699: Remove no-op CClientUIInterface::[signal_name]_disconne…
Browse files Browse the repository at this point in the history
…ct. Disconnect BlockNotifyGenesisWait and RPCNotifyBlockChange properly.

6dd469a Disconnect BlockNotifyGenesisWait and RPCNotifyBlockChange properly. Remove no-op CClientUIInterface::[signal_name]_disconnect. (practicalswift)

Pull request description:

  Resolves #15698.

  Changes:
  * Remove no-op `CClientUIInterface::[signal_name]_disconnect`.
  * Disconnect `BlockNotifyGenesisWait` and `RPCNotifyBlockChange` properly.

ACKs for commit 6dd469:
  MarcoFalke:
    utACK 6dd469a

Tree-SHA512: 0b50d658fa72261332bc57ddea379fd08f4bc1de392c10c628e20142d6fd244b606c39fd0665d6bc39324c1aa8c8814ac942b4659106279e33b90206aaf37411
  • Loading branch information
MarcoFalke committed Apr 23, 2019
2 parents e9e777e + 6dd469a commit 4bd7187
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/init.cpp
Expand Up @@ -345,14 +345,15 @@ static void registerSignalHandler(int signal, void(*handler)(int))
}
#endif

static boost::signals2::connection rpc_notify_block_change_connection;
static void OnRPCStarted()
{
uiInterface.NotifyBlockTip_connect(&RPCNotifyBlockChange);
rpc_notify_block_change_connection = uiInterface.NotifyBlockTip_connect(&RPCNotifyBlockChange);
}

static void OnRPCStopped()
{
uiInterface.NotifyBlockTip_disconnect(&RPCNotifyBlockChange);
rpc_notify_block_change_connection.disconnect();
RPCNotifyBlockChange(false, nullptr);
g_best_block_cv.notify_all();
LogPrint(BCLog::RPC, "RPC stopped.\n");
Expand Down Expand Up @@ -1733,8 +1734,9 @@ bool AppInitMain(InitInterfaces& interfaces)

// Either install a handler to notify us when genesis activates, or set fHaveGenesis directly.
// No locking, as this happens before any background thread is started.
boost::signals2::connection block_notify_genesis_wait_connection;
if (chainActive.Tip() == nullptr) {
uiInterface.NotifyBlockTip_connect(BlockNotifyGenesisWait);
block_notify_genesis_wait_connection = uiInterface.NotifyBlockTip_connect(BlockNotifyGenesisWait);
} else {
fHaveGenesis = true;
}
Expand All @@ -1758,7 +1760,7 @@ bool AppInitMain(InitInterfaces& interfaces)
while (!fHaveGenesis && !ShutdownRequested()) {
g_genesis_wait_cv.wait_for(lock, std::chrono::milliseconds(500));
}
uiInterface.NotifyBlockTip_disconnect(BlockNotifyGenesisWait);
block_notify_genesis_wait_connection.disconnect();
}

if (ShutdownRequested()) {
Expand Down
4 changes: 0 additions & 4 deletions src/ui_interface.cpp
Expand Up @@ -28,10 +28,6 @@ struct UISignals {
boost::signals2::connection CClientUIInterface::signal_name##_connect(std::function<signal_name##Sig> fn) \
{ \
return g_ui_signals.signal_name.connect(fn); \
} \
void CClientUIInterface::signal_name##_disconnect(std::function<signal_name##Sig> fn) \
{ \
return g_ui_signals.signal_name.disconnect(&fn); \
}

ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeMessageBox);
Expand Down
3 changes: 1 addition & 2 deletions src/ui_interface.h
Expand Up @@ -81,8 +81,7 @@ class CClientUIInterface
#define ADD_SIGNALS_DECL_WRAPPER(signal_name, rtype, ...) \
rtype signal_name(__VA_ARGS__); \
using signal_name##Sig = rtype(__VA_ARGS__); \
boost::signals2::connection signal_name##_connect(std::function<signal_name##Sig> fn); \
void signal_name##_disconnect(std::function<signal_name##Sig> fn);
boost::signals2::connection signal_name##_connect(std::function<signal_name##Sig> fn);

/** Show message box. */
ADD_SIGNALS_DECL_WRAPPER(ThreadSafeMessageBox, bool, const std::string& message, const std::string& caption, unsigned int style);
Expand Down

0 comments on commit 4bd7187

Please sign in to comment.