Skip to content

Commit 33357b2

Browse files
committed
qt: Start core thread only when needed
Start the core thread only when needed for initialization or shutdown. Avoids a bit of overhead, and also avoids spamming two log messages before logging is properly initialized.
1 parent c715ff5 commit 33357b2

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/qt/bitcoin.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,17 @@ BitcoinApplication::BitcoinApplication(int &argc, char **argv):
286286
returnValue(0)
287287
{
288288
setQuitOnLastWindowClosed(false);
289-
startThread();
290289
}
291290

292291
BitcoinApplication::~BitcoinApplication()
293292
{
294-
qDebug() << __func__ << ": Stopping thread";
295-
emit stopThread();
296-
coreThread->wait();
297-
qDebug() << __func__ << ": Stopped thread";
293+
if(coreThread)
294+
{
295+
qDebug() << __func__ << ": Stopping thread";
296+
emit stopThread();
297+
coreThread->wait();
298+
qDebug() << __func__ << ": Stopped thread";
299+
}
298300

299301
delete window;
300302
window = 0;
@@ -337,6 +339,8 @@ void BitcoinApplication::createSplashScreen(bool isaTestNet)
337339

338340
void BitcoinApplication::startThread()
339341
{
342+
if(coreThread)
343+
return;
340344
coreThread = new QThread(this);
341345
BitcoinCore *executor = new BitcoinCore();
342346
executor->moveToThread(coreThread);
@@ -357,12 +361,14 @@ void BitcoinApplication::startThread()
357361
void BitcoinApplication::requestInitialize()
358362
{
359363
qDebug() << __func__ << ": Requesting initialize";
364+
startThread();
360365
emit requestedInitialize();
361366
}
362367

363368
void BitcoinApplication::requestShutdown()
364369
{
365370
qDebug() << __func__ << ": Requesting shutdown";
371+
startThread();
366372
window->hide();
367373
window->setClientModel(0);
368374
pollShutdownTimer->stop();

0 commit comments

Comments
 (0)