Skip to content

Commit fa2e443

Browse files
author
MarcoFalke
committed
refactor: Replace g_genesis_wait_cv with m_tip_block_cv
They achieve the same, but the extra indirection over boost::signals2 is not needed.
1 parent fa7f52a commit fa2e443

File tree

1 file changed

+7
-34
lines changed

1 file changed

+7
-34
lines changed

src/init.cpp

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -685,21 +685,6 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
685685
argsman.AddHiddenArgs(hidden_args);
686686
}
687687

688-
static bool fHaveGenesis = false;
689-
static GlobalMutex g_genesis_wait_mutex;
690-
static std::condition_variable g_genesis_wait_cv;
691-
692-
static void BlockNotifyGenesisWait(const CBlockIndex* pBlockIndex)
693-
{
694-
if (pBlockIndex != nullptr) {
695-
{
696-
LOCK(g_genesis_wait_mutex);
697-
fHaveGenesis = true;
698-
}
699-
g_genesis_wait_cv.notify_all();
700-
}
701-
}
702-
703688
#if HAVE_SYSTEM
704689
static void StartupNotify(const ArgsManager& args)
705690
{
@@ -1616,7 +1601,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
16161601
// ********************************************************* Step 7: load block chain
16171602

16181603
node.notifications = std::make_unique<KernelNotifications>(Assert(node.shutdown_request), node.exit_status, *Assert(node.warnings));
1619-
ReadNotificationArgs(args, *node.notifications);
1604+
auto& kernel_notifications{*node.notifications};
1605+
ReadNotificationArgs(args, kernel_notifications);
16201606

16211607
// cache size calculations
16221608
CacheSizes cache_sizes = CalculateCacheSizes(args, g_enabled_filter_types.size());
@@ -1768,15 +1754,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
17681754
}
17691755
}
17701756

1771-
// Either install a handler to notify us when genesis activates, or set fHaveGenesis directly.
1772-
// No locking, as this happens before any background thread is started.
1773-
boost::signals2::connection block_notify_genesis_wait_connection;
1774-
if (WITH_LOCK(chainman.GetMutex(), return chainman.ActiveChain().Tip() == nullptr)) {
1775-
block_notify_genesis_wait_connection = uiInterface.NotifyBlockTip_connect(std::bind(BlockNotifyGenesisWait, std::placeholders::_2));
1776-
} else {
1777-
fHaveGenesis = true;
1778-
}
1779-
17801757
#if HAVE_SYSTEM
17811758
const std::string block_notify = args.GetArg("-blocknotify", "");
17821759
if (!block_notify.empty()) {
@@ -1821,15 +1798,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
18211798
});
18221799

18231800
// Wait for genesis block to be processed
1824-
{
1825-
WAIT_LOCK(g_genesis_wait_mutex, lock);
1826-
// We previously could hang here if shutdown was requested prior to
1827-
// ImportBlocks getting started, so instead we just wait on a timer to
1828-
// check ShutdownRequested() regularly.
1829-
while (!fHaveGenesis && !ShutdownRequested(node)) {
1830-
g_genesis_wait_cv.wait_for(lock, std::chrono::milliseconds(500));
1831-
}
1832-
block_notify_genesis_wait_connection.disconnect();
1801+
if (WITH_LOCK(chainman.GetMutex(), return chainman.ActiveTip() == nullptr)) {
1802+
WAIT_LOCK(kernel_notifications.m_tip_block_mutex, lock);
1803+
kernel_notifications.m_tip_block_cv.wait(lock, [&]() EXCLUSIVE_LOCKS_REQUIRED(kernel_notifications.m_tip_block_mutex) {
1804+
return !kernel_notifications.m_tip_block.IsNull() || ShutdownRequested(node);
1805+
});
18331806
}
18341807

18351808
if (ShutdownRequested(node)) {

0 commit comments

Comments
 (0)