Skip to content

Commit 792be53

Browse files
committed
refactor: Replace std::bind with lambdas
Lambdas are shorter and more readable. Changes are limited to std::thread ctor calls only.
1 parent a508f71 commit 792be53

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/index/base.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,7 @@ void BaseIndex::Start()
349349
return;
350350
}
351351

352-
m_thread_sync = std::thread(&util::TraceThread, GetName(),
353-
std::bind(&BaseIndex::ThreadSync, this));
352+
m_thread_sync = std::thread(&util::TraceThread, GetName(), [this] { ThreadSync(); });
354353
}
355354

356355
void BaseIndex::Stop()

src/net.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,15 +2528,15 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
25282528
}
25292529

25302530
// Send and receive from sockets, accept connections
2531-
threadSocketHandler = std::thread(&util::TraceThread, "net", std::bind(&CConnman::ThreadSocketHandler, this));
2531+
threadSocketHandler = std::thread(&util::TraceThread, "net", [this] { ThreadSocketHandler(); });
25322532

25332533
if (!gArgs.GetBoolArg("-dnsseed", DEFAULT_DNSSEED))
25342534
LogPrintf("DNS seeding disabled\n");
25352535
else
2536-
threadDNSAddressSeed = std::thread(&util::TraceThread, "dnsseed", std::bind(&CConnman::ThreadDNSAddressSeed, this));
2536+
threadDNSAddressSeed = std::thread(&util::TraceThread, "dnsseed", [this] { ThreadDNSAddressSeed(); });
25372537

25382538
// Initiate manual connections
2539-
threadOpenAddedConnections = std::thread(&util::TraceThread, "addcon", std::bind(&CConnman::ThreadOpenAddedConnections, this));
2539+
threadOpenAddedConnections = std::thread(&util::TraceThread, "addcon", [this] { ThreadOpenAddedConnections(); });
25402540

25412541
if (connOptions.m_use_addrman_outgoing && !connOptions.m_specified_outgoing.empty()) {
25422542
if (clientInterface) {
@@ -2546,16 +2546,18 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
25462546
}
25472547
return false;
25482548
}
2549-
if (connOptions.m_use_addrman_outgoing || !connOptions.m_specified_outgoing.empty())
2550-
threadOpenConnections = std::thread(&util::TraceThread, "opencon", std::bind(&CConnman::ThreadOpenConnections, this, connOptions.m_specified_outgoing));
2549+
if (connOptions.m_use_addrman_outgoing || !connOptions.m_specified_outgoing.empty()) {
2550+
threadOpenConnections = std::thread(
2551+
&util::TraceThread, "opencon",
2552+
[this, connect = connOptions.m_specified_outgoing] { ThreadOpenConnections(connect); });
2553+
}
25512554

25522555
// Process messages
2553-
threadMessageHandler = std::thread(&util::TraceThread, "msghand", std::bind(&CConnman::ThreadMessageHandler, this));
2556+
threadMessageHandler = std::thread(&util::TraceThread, "msghand", [this] { ThreadMessageHandler(); });
25542557

25552558
if (connOptions.m_i2p_accept_incoming && m_i2p_sam_session.get() != nullptr) {
25562559
threadI2PAcceptIncoming =
2557-
std::thread(&util::TraceThread, "i2paccept",
2558-
std::function<void()>(std::bind(&CConnman::ThreadI2PAcceptIncoming, this)));
2560+
std::thread(&util::TraceThread, "i2paccept", [this] { ThreadI2PAcceptIncoming(); });
25592561
}
25602562

25612563
// Dump network addresses

0 commit comments

Comments
 (0)