Skip to content

Commit 9a1dcea

Browse files
committed
Use CScheduler for net's DumpAddresses
Instead of starting Yet Another Thread to dump addresses, use CScheduler to do it.
1 parent ddd0acd commit 9a1dcea

File tree

4 files changed

+6
-41
lines changed

4 files changed

+6
-41
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
13781378
LogPrintf("mapAddressBook.size() = %u\n", pwalletMain ? pwalletMain->mapAddressBook.size() : 0);
13791379
#endif
13801380

1381-
StartNode(threadGroup);
1381+
StartNode(threadGroup, scheduler);
13821382

13831383
#ifdef ENABLE_WALLET
13841384
// Generate coins in the background

src/net.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "chainparams.h"
1414
#include "clientversion.h"
1515
#include "primitives/transaction.h"
16+
#include "scheduler.h"
1617
#include "ui_interface.h"
1718
#include "crypto/common.h"
1819

@@ -1590,7 +1591,7 @@ void static Discover(boost::thread_group& threadGroup)
15901591
#endif
15911592
}
15921593

1593-
void StartNode(boost::thread_group& threadGroup)
1594+
void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler)
15941595
{
15951596
uiInterface.InitMessage(_("Loading addresses..."));
15961597
// Load addresses for peers.dat
@@ -1640,7 +1641,7 @@ void StartNode(boost::thread_group& threadGroup)
16401641
threadGroup.create_thread(boost::bind(&TraceThread<void (*)()>, "msghand", &ThreadMessageHandler));
16411642

16421643
// Dump network addresses
1643-
threadGroup.create_thread(boost::bind(&LoopForever<void (*)()>, "dumpaddr", &DumpAddresses, DUMP_ADDRESSES_INTERVAL * 1000));
1644+
scheduler.scheduleEvery(&DumpAddresses, DUMP_ADDRESSES_INTERVAL);
16441645
}
16451646

16461647
bool StopNode()

src/net.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
class CAddrMan;
3434
class CBlockIndex;
35+
class CScheduler;
3536
class CNode;
3637

3738
namespace boost {
@@ -72,7 +73,7 @@ bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOu
7273
void MapPort(bool fUseUPnP);
7374
unsigned short GetListenPort();
7475
bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
75-
void StartNode(boost::thread_group& threadGroup);
76+
void StartNode(boost::thread_group& threadGroup, CScheduler& scheduler);
7677
bool StopNode();
7778
void SocketSendData(CNode *pnode);
7879

src/util.h

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -202,43 +202,6 @@ std::string HelpMessageOpt(const std::string& option, const std::string& message
202202
void SetThreadPriority(int nPriority);
203203
void RenameThread(const char* name);
204204

205-
/**
206-
* Standard wrapper for do-something-forever thread functions.
207-
* "Forever" really means until the thread is interrupted.
208-
* Use it like:
209-
* new boost::thread(boost::bind(&LoopForever<void (*)()>, "dumpaddr", &DumpAddresses, 900000));
210-
* or maybe:
211-
* boost::function<void()> f = boost::bind(&FunctionWithArg, argument);
212-
* threadGroup.create_thread(boost::bind(&LoopForever<boost::function<void()> >, "nothing", f, milliseconds));
213-
*/
214-
template <typename Callable> void LoopForever(const char* name, Callable func, int64_t msecs)
215-
{
216-
std::string s = strprintf("bitcoin-%s", name);
217-
RenameThread(s.c_str());
218-
LogPrintf("%s thread start\n", name);
219-
try
220-
{
221-
while (1)
222-
{
223-
MilliSleep(msecs);
224-
func();
225-
}
226-
}
227-
catch (const boost::thread_interrupted&)
228-
{
229-
LogPrintf("%s thread stop\n", name);
230-
throw;
231-
}
232-
catch (const std::exception& e) {
233-
PrintExceptionContinue(&e, name);
234-
throw;
235-
}
236-
catch (...) {
237-
PrintExceptionContinue(NULL, name);
238-
throw;
239-
}
240-
}
241-
242205
/**
243206
* .. and a wrapper that just calls func once
244207
*/

0 commit comments

Comments
 (0)