mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-12 16:17:53 +00:00
Get rid of DetectShutdownThread
The main thread spends time waiting for the DetectShutdownThread. So why not just run this waiting loop function in the main thread? One thread-stack less saves 4MB of virtual memory on 32-bit, and 8MB on 64-bit.
This commit is contained in:
parent
e1aecae33a
commit
28ee7e8b8c
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
static bool fDaemon;
|
static bool fDaemon;
|
||||||
|
|
||||||
void DetectShutdownThread(boost::thread_group* threadGroup)
|
void WaitForShutdown(boost::thread_group* threadGroup)
|
||||||
{
|
{
|
||||||
bool fShutdown = ShutdownRequested();
|
bool fShutdown = ShutdownRequested();
|
||||||
// Tell the main threads to shutdown.
|
// Tell the main threads to shutdown.
|
||||||
@ -56,7 +56,6 @@ void DetectShutdownThread(boost::thread_group* threadGroup)
|
|||||||
bool AppInit(int argc, char* argv[])
|
bool AppInit(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
boost::thread_group threadGroup;
|
boost::thread_group threadGroup;
|
||||||
boost::thread* detectShutdownThread = NULL;
|
|
||||||
|
|
||||||
bool fRet = false;
|
bool fRet = false;
|
||||||
|
|
||||||
@ -144,7 +143,6 @@ bool AppInit(int argc, char* argv[])
|
|||||||
#endif
|
#endif
|
||||||
SoftSetBoolArg("-server", true);
|
SoftSetBoolArg("-server", true);
|
||||||
|
|
||||||
detectShutdownThread = new boost::thread(boost::bind(&DetectShutdownThread, &threadGroup));
|
|
||||||
fRet = AppInit2(threadGroup);
|
fRet = AppInit2(threadGroup);
|
||||||
}
|
}
|
||||||
catch (const std::exception& e) {
|
catch (const std::exception& e) {
|
||||||
@ -155,20 +153,12 @@ bool AppInit(int argc, char* argv[])
|
|||||||
|
|
||||||
if (!fRet)
|
if (!fRet)
|
||||||
{
|
{
|
||||||
if (detectShutdownThread)
|
|
||||||
detectShutdownThread->interrupt();
|
|
||||||
|
|
||||||
threadGroup.interrupt_all();
|
threadGroup.interrupt_all();
|
||||||
// threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
|
// threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
|
||||||
// the startup-failure cases to make sure they don't result in a hang due to some
|
// the startup-failure cases to make sure they don't result in a hang due to some
|
||||||
// thread-blocking-waiting-for-another-thread-during-startup case
|
// thread-blocking-waiting-for-another-thread-during-startup case
|
||||||
}
|
} else {
|
||||||
|
WaitForShutdown(&threadGroup);
|
||||||
if (detectShutdownThread)
|
|
||||||
{
|
|
||||||
detectShutdownThread->join();
|
|
||||||
delete detectShutdownThread;
|
|
||||||
detectShutdownThread = NULL;
|
|
||||||
}
|
}
|
||||||
Shutdown();
|
Shutdown();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user