Skip to content

Commit cbb91cd

Browse files
author
MarcoFalke
committed
Merge #13743: refactor: Replace boost::bind with std::bind
cb53b82 scripted-diff: Replace boost::bind with std::bind (Chun Kuan Lee) 2196c51 refactor: Use boost::scoped_connection in signal/slot, also prefer range-based loop instead of std::transform (Chun Kuan Lee) Pull request description: Replace boost::bind with std::bind - In `src/rpc/server.cpp`, replace `std::transform` with simple loop. - In `src/validation.cpp`, store the `boost::signals2::connection` object and use it to disconnect. - In `src/validationinterface.cpp`, use 2 map to store the `boost::signals2::scoped_connection` object. Tree-SHA512: 6653cbe00036fecfc495340618efcba6d7be0227c752b37b81a27184433330f817e8de9257774e9b35828026cb55f11ee7f17d6c388aebe22c4a3df13b5092f0
2 parents 3c9b98b + cb53b82 commit cbb91cd

17 files changed

+83
-96
lines changed

src/bench/block_assemble.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static void AssembleBlock(benchmark::State& state)
7878
::pcoinsTip.reset(new CCoinsViewCache(pcoinsdbview.get()));
7979

8080
const CChainParams& chainparams = Params();
81-
thread_group.create_thread(boost::bind(&CScheduler::serviceQueue, &scheduler));
81+
thread_group.create_thread(std::bind(&CScheduler::serviceQueue, &scheduler));
8282
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
8383
LoadGenesisBlock(chainparams);
8484
CValidationState state;

src/init.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
#include <boost/algorithm/string/classification.hpp>
6060
#include <boost/algorithm/string/replace.hpp>
6161
#include <boost/algorithm/string/split.hpp>
62-
#include <boost/bind.hpp>
6362
#include <boost/thread.hpp>
6463
#include <openssl/crypto.h>
6564

@@ -1237,8 +1236,8 @@ bool AppInitMain(InitInterfaces& interfaces)
12371236
}
12381237

12391238
// Start the lightweight task scheduler thread
1240-
CScheduler::Function serviceLoop = boost::bind(&CScheduler::serviceQueue, &scheduler);
1241-
threadGroup.create_thread(boost::bind(&TraceThread<CScheduler::Function>, "scheduler", serviceLoop));
1239+
CScheduler::Function serviceLoop = std::bind(&CScheduler::serviceQueue, &scheduler);
1240+
threadGroup.create_thread(std::bind(&TraceThread<CScheduler::Function>, "scheduler", serviceLoop));
12421241

12431242
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
12441243
GetMainSignals().RegisterWithMempoolSignals(mempool);
@@ -1646,7 +1645,7 @@ bool AppInitMain(InitInterfaces& interfaces)
16461645
vImportFiles.push_back(strFile);
16471646
}
16481647

1649-
threadGroup.create_thread(boost::bind(&ThreadImport, vImportFiles));
1648+
threadGroup.create_thread(std::bind(&ThreadImport, vImportFiles));
16501649

16511650
// Wait for genesis block to be processed
16521651
{

src/qt/bitcoingui.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
#include <QVBoxLayout>
5959
#include <QWindow>
6060

61-
#include <boost/bind.hpp>
6261

6362
const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
6463
#if defined(Q_OS_MAC)
@@ -1294,8 +1293,8 @@ static bool ThreadSafeMessageBox(BitcoinGUI* gui, const std::string& message, co
12941293
void BitcoinGUI::subscribeToCoreSignals()
12951294
{
12961295
// Connect signals to client
1297-
m_handler_message_box = m_node.handleMessageBox(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3));
1298-
m_handler_question = m_node.handleQuestion(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4));
1296+
m_handler_message_box = m_node.handleMessageBox(std::bind(ThreadSafeMessageBox, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
1297+
m_handler_question = m_node.handleQuestion(std::bind(ThreadSafeMessageBox, this, std::placeholders::_1, std::placeholders::_3, std::placeholders::_4));
12991298
}
13001299

13011300
void BitcoinGUI::unsubscribeFromCoreSignals()

src/qt/clientmodel.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,13 @@ static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, int heig
252252
void ClientModel::subscribeToCoreSignals()
253253
{
254254
// Connect signals to client
255-
m_handler_show_progress = m_node.handleShowProgress(boost::bind(ShowProgress, this, _1, _2));
256-
m_handler_notify_num_connections_changed = m_node.handleNotifyNumConnectionsChanged(boost::bind(NotifyNumConnectionsChanged, this, _1));
257-
m_handler_notify_network_active_changed = m_node.handleNotifyNetworkActiveChanged(boost::bind(NotifyNetworkActiveChanged, this, _1));
258-
m_handler_notify_alert_changed = m_node.handleNotifyAlertChanged(boost::bind(NotifyAlertChanged, this));
259-
m_handler_banned_list_changed = m_node.handleBannedListChanged(boost::bind(BannedListChanged, this));
260-
m_handler_notify_block_tip = m_node.handleNotifyBlockTip(boost::bind(BlockTipChanged, this, _1, _2, _3, _4, false));
261-
m_handler_notify_header_tip = m_node.handleNotifyHeaderTip(boost::bind(BlockTipChanged, this, _1, _2, _3, _4, true));
255+
m_handler_show_progress = m_node.handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2));
256+
m_handler_notify_num_connections_changed = m_node.handleNotifyNumConnectionsChanged(std::bind(NotifyNumConnectionsChanged, this, std::placeholders::_1));
257+
m_handler_notify_network_active_changed = m_node.handleNotifyNetworkActiveChanged(std::bind(NotifyNetworkActiveChanged, this, std::placeholders::_1));
258+
m_handler_notify_alert_changed = m_node.handleNotifyAlertChanged(std::bind(NotifyAlertChanged, this));
259+
m_handler_banned_list_changed = m_node.handleBannedListChanged(std::bind(BannedListChanged, this));
260+
m_handler_notify_block_tip = m_node.handleNotifyBlockTip(std::bind(BlockTipChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, false));
261+
m_handler_notify_header_tip = m_node.handleNotifyHeaderTip(std::bind(BlockTipChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, true));
262262
}
263263

264264
void ClientModel::unsubscribeFromCoreSignals()

src/qt/splashscreen.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <QPainter>
2525
#include <QRadialGradient>
2626

27-
#include <boost/bind.hpp>
2827

2928
SplashScreen::SplashScreen(interfaces::Node& node, Qt::WindowFlags f, const NetworkStyle *networkStyle) :
3029
QWidget(0, f), curAlignment(0), m_node(node)
@@ -174,16 +173,16 @@ static void ShowProgress(SplashScreen *splash, const std::string &title, int nPr
174173
#ifdef ENABLE_WALLET
175174
void SplashScreen::ConnectWallet(std::unique_ptr<interfaces::Wallet> wallet)
176175
{
177-
m_connected_wallet_handlers.emplace_back(wallet->handleShowProgress(boost::bind(ShowProgress, this, _1, _2, false)));
176+
m_connected_wallet_handlers.emplace_back(wallet->handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2, false)));
178177
m_connected_wallets.emplace_back(std::move(wallet));
179178
}
180179
#endif
181180

182181
void SplashScreen::subscribeToCoreSignals()
183182
{
184183
// Connect signals to client
185-
m_handler_init_message = m_node.handleInitMessage(boost::bind(InitMessage, this, _1));
186-
m_handler_show_progress = m_node.handleShowProgress(boost::bind(ShowProgress, this, _1, _2, _3));
184+
m_handler_init_message = m_node.handleInitMessage(std::bind(InitMessage, this, std::placeholders::_1));
185+
m_handler_show_progress = m_node.handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
187186
#ifdef ENABLE_WALLET
188187
m_handler_load_wallet = m_node.handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) { ConnectWallet(std::move(wallet)); });
189188
#endif

src/qt/transactiontablemodel.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <QIcon>
2828
#include <QList>
2929

30-
#include <boost/bind.hpp>
3130

3231
// Amount column is right-aligned it contains numbers
3332
static int column_alignments[] = {
@@ -745,8 +744,8 @@ static void ShowProgress(TransactionTableModel *ttm, const std::string &title, i
745744
void TransactionTableModel::subscribeToCoreSignals()
746745
{
747746
// Connect signals to wallet
748-
m_handler_transaction_changed = walletModel->wallet().handleTransactionChanged(boost::bind(NotifyTransactionChanged, this, _1, _2));
749-
m_handler_show_progress = walletModel->wallet().handleShowProgress(boost::bind(ShowProgress, this, _1, _2));
747+
m_handler_transaction_changed = walletModel->wallet().handleTransactionChanged(std::bind(NotifyTransactionChanged, this, std::placeholders::_1, std::placeholders::_2));
748+
m_handler_show_progress = walletModel->wallet().handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2));
750749
}
751750

752751
void TransactionTableModel::unsubscribeFromCoreSignals()

src/qt/walletmodel.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,12 +428,12 @@ static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly
428428
void WalletModel::subscribeToCoreSignals()
429429
{
430430
// Connect signals to wallet
431-
m_handler_unload = m_wallet->handleUnload(boost::bind(&NotifyUnload, this));
432-
m_handler_status_changed = m_wallet->handleStatusChanged(boost::bind(&NotifyKeyStoreStatusChanged, this));
433-
m_handler_address_book_changed = m_wallet->handleAddressBookChanged(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5));
434-
m_handler_transaction_changed = m_wallet->handleTransactionChanged(boost::bind(NotifyTransactionChanged, this, _1, _2));
435-
m_handler_show_progress = m_wallet->handleShowProgress(boost::bind(ShowProgress, this, _1, _2));
436-
m_handler_watch_only_changed = m_wallet->handleWatchOnlyChanged(boost::bind(NotifyWatchonlyChanged, this, _1));
431+
m_handler_unload = m_wallet->handleUnload(std::bind(&NotifyUnload, this));
432+
m_handler_status_changed = m_wallet->handleStatusChanged(std::bind(&NotifyKeyStoreStatusChanged, this));
433+
m_handler_address_book_changed = m_wallet->handleAddressBookChanged(std::bind(NotifyAddressBookChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5));
434+
m_handler_transaction_changed = m_wallet->handleTransactionChanged(std::bind(NotifyTransactionChanged, this, std::placeholders::_1, std::placeholders::_2));
435+
m_handler_show_progress = m_wallet->handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2));
436+
m_handler_watch_only_changed = m_wallet->handleWatchOnlyChanged(std::bind(NotifyWatchonlyChanged, this, std::placeholders::_1));
437437
}
438438

439439
void WalletModel::unsubscribeFromCoreSignals()

src/rpc/server.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <util/strencodings.h>
1616
#include <util/system.h>
1717

18-
#include <boost/bind.hpp>
1918
#include <boost/signals2/signal.hpp>
2019
#include <boost/algorithm/string/classification.hpp>
2120
#include <boost/algorithm/string/split.hpp>
@@ -504,11 +503,7 @@ UniValue CRPCTable::execute(const JSONRPCRequest &request) const
504503
std::vector<std::string> CRPCTable::listCommands() const
505504
{
506505
std::vector<std::string> commandList;
507-
typedef std::map<std::string, const CRPCCommand*> commandMap;
508-
509-
std::transform( mapCommands.begin(), mapCommands.end(),
510-
std::back_inserter(commandList),
511-
boost::bind(&commandMap::value_type::first,_1) );
506+
for (const auto& i : mapCommands) commandList.emplace_back(i.first);
512507
return commandList;
513508
}
514509

src/scheduler.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <reverselock.h>
99

1010
#include <assert.h>
11-
#include <boost/bind.hpp>
1211
#include <utility>
1312

1413
CScheduler::CScheduler() : nThreadsServicingQueue(0), stopRequested(false), stopWhenEmpty(false)
@@ -120,12 +119,12 @@ void CScheduler::scheduleFromNow(CScheduler::Function f, int64_t deltaMilliSecon
120119
static void Repeat(CScheduler* s, CScheduler::Function f, int64_t deltaMilliSeconds)
121120
{
122121
f();
123-
s->scheduleFromNow(boost::bind(&Repeat, s, f, deltaMilliSeconds), deltaMilliSeconds);
122+
s->scheduleFromNow(std::bind(&Repeat, s, f, deltaMilliSeconds), deltaMilliSeconds);
124123
}
125124

126125
void CScheduler::scheduleEvery(CScheduler::Function f, int64_t deltaMilliSeconds)
127126
{
128-
scheduleFromNow(boost::bind(&Repeat, this, f, deltaMilliSeconds), deltaMilliSeconds);
127+
scheduleFromNow(std::bind(&Repeat, this, f, deltaMilliSeconds), deltaMilliSeconds);
129128
}
130129

131130
size_t CScheduler::getQueueInfo(boost::chrono::system_clock::time_point &first,

src/scheduler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// CScheduler* s = new CScheduler();
2626
// s->scheduleFromNow(doSomething, 11); // Assuming a: void doSomething() { }
2727
// s->scheduleFromNow(std::bind(Class::func, this, argument), 3);
28-
// boost::thread* t = new boost::thread(boost::bind(CScheduler::serviceQueue, s));
28+
// boost::thread* t = new boost::thread(std::bind(CScheduler::serviceQueue, s));
2929
//
3030
// ... then at program shutdown, clean up the thread running serviceQueue:
3131
// t->interrupt();

0 commit comments

Comments
 (0)