Skip to content

Commit 66f3d06

Browse files
committed
Merge pull request #4534
33357b2 qt: Start core thread only when needed (Wladimir J. van der Laan) c715ff5 ui: Replace some LogPrintfs with qDebug() (Wladimir J. van der Laan) 96ff9d6 Can't log to debug log before chain params initialized (Wladimir J. van der Laan)
2 parents 00b16bc + 33357b2 commit 66f3d06

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

src/chainparamsbase.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,7 @@ bool SelectBaseParamsFromCommandLine() {
9191
}
9292
return true;
9393
}
94+
95+
bool AreBaseParamsConfigured() {
96+
return pCurrentBaseParams != NULL;
97+
}

src/chainparamsbase.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,10 @@ void SelectBaseParams(CBaseChainParams::Network network);
4949
*/
5050
bool SelectBaseParamsFromCommandLine();
5151

52+
/**
53+
* Return true if SelectBaseParamsFromCommandLine() has been called to select
54+
* a network.
55+
*/
56+
bool AreBaseParamsConfigured();
57+
5258
#endif

src/qt/bitcoin.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#include <boost/filesystem/operations.hpp>
3636
#include <QApplication>
37+
#include <QDebug>
3738
#include <QLibraryInfo>
3839
#include <QLocale>
3940
#include <QMessageBox>
@@ -237,7 +238,7 @@ void BitcoinCore::initialize()
237238
{
238239
try
239240
{
240-
LogPrintf("Running AppInit2 in thread\n");
241+
qDebug() << __func__ << ": Running AppInit2 in thread";
241242
int rv = AppInit2(threadGroup);
242243
if(rv)
243244
{
@@ -258,11 +259,11 @@ void BitcoinCore::shutdown()
258259
{
259260
try
260261
{
261-
LogPrintf("Running Shutdown in thread\n");
262+
qDebug() << __func__ << ": Running Shutdown in thread";
262263
threadGroup.interrupt_all();
263264
threadGroup.join_all();
264265
Shutdown();
265-
LogPrintf("Shutdown finished\n");
266+
qDebug() << __func__ << ": Shutdown finished";
266267
emit shutdownResult(1);
267268
} catch (std::exception& e) {
268269
handleRunawayException(&e);
@@ -285,15 +286,17 @@ BitcoinApplication::BitcoinApplication(int &argc, char **argv):
285286
returnValue(0)
286287
{
287288
setQuitOnLastWindowClosed(false);
288-
startThread();
289289
}
290290

291291
BitcoinApplication::~BitcoinApplication()
292292
{
293-
LogPrintf("Stopping thread\n");
294-
emit stopThread();
295-
coreThread->wait();
296-
LogPrintf("Stopped thread\n");
293+
if(coreThread)
294+
{
295+
qDebug() << __func__ << ": Stopping thread";
296+
emit stopThread();
297+
coreThread->wait();
298+
qDebug() << __func__ << ": Stopped thread";
299+
}
297300

298301
delete window;
299302
window = 0;
@@ -336,6 +339,8 @@ void BitcoinApplication::createSplashScreen(bool isaTestNet)
336339

337340
void BitcoinApplication::startThread()
338341
{
342+
if(coreThread)
343+
return;
339344
coreThread = new QThread(this);
340345
BitcoinCore *executor = new BitcoinCore();
341346
executor->moveToThread(coreThread);
@@ -355,13 +360,15 @@ void BitcoinApplication::startThread()
355360

356361
void BitcoinApplication::requestInitialize()
357362
{
358-
LogPrintf("Requesting initialize\n");
363+
qDebug() << __func__ << ": Requesting initialize";
364+
startThread();
359365
emit requestedInitialize();
360366
}
361367

362368
void BitcoinApplication::requestShutdown()
363369
{
364-
LogPrintf("Requesting shutdown\n");
370+
qDebug() << __func__ << ": Requesting shutdown";
371+
startThread();
365372
window->hide();
366373
window->setClientModel(0);
367374
pollShutdownTimer->stop();
@@ -383,7 +390,7 @@ void BitcoinApplication::requestShutdown()
383390

384391
void BitcoinApplication::initializeResult(int retval)
385392
{
386-
LogPrintf("Initialization result: %i\n", retval);
393+
qDebug() << __func__ << ": Initialization result: " << retval;
387394
// Set exit result: 0 if successful, 1 if failure
388395
returnValue = retval ? 0 : 1;
389396
if(retval)
@@ -438,7 +445,7 @@ void BitcoinApplication::initializeResult(int retval)
438445

439446
void BitcoinApplication::shutdownResult(int retval)
440447
{
441-
LogPrintf("Shutdown result: %i\n", retval);
448+
qDebug() << __func__ << ": Shutdown result: " << retval;
442449
quit(); // Exit main loop after shutdown finished
443450
}
444451

src/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ int LogPrintStr(const std::string &str)
205205
// print to console
206206
ret = fwrite(str.data(), 1, str.size(), stdout);
207207
}
208-
else if (fPrintToDebugLog)
208+
else if (fPrintToDebugLog && AreBaseParamsConfigured())
209209
{
210210
static bool fStartedNewLine = true;
211211
boost::call_once(&DebugPrintInit, debugPrintInitFlag);

0 commit comments

Comments
 (0)