diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2013-03-06 22:16:05 -0500 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2013-04-03 14:04:21 -0400 |
commit | c8c2fbe07f1a5475aea3a2680af9130558c7e5c8 (patch) | |
tree | 78e8007fa6898d8f7f6826ab59c0bab8a4aae417 /src/init.cpp | |
parent | 87b9931bed5ec6633348ac506f0e9b5a96446df8 (diff) |
Shutdown cleanup prep-work
Create a boost::thread_group object at the qt/bitcoind main-loop level
that will hold pointers to all the main-loop threads.
This will replace the vnThreadsRunning[] array.
For testing, ported the BitcoinMiner threads to use its
own boost::thread_group.
Diffstat (limited to 'src/init.cpp')
-rw-r--r-- | src/init.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/init.cpp b/src/init.cpp index aac46d489d..a5015adc48 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -122,6 +122,16 @@ void Shutdown(void* parg) } } +// +// Signal handlers are very limited in what they are allowed to do, so: +// +void DetectShutdownThread(boost::thread_group* threadGroup) +{ + while (fRequestShutdown == false) + Sleep(200); + threadGroup->interrupt_all(); +} + void HandleSIGTERM(int) { fRequestShutdown = true; @@ -143,6 +153,7 @@ void HandleSIGHUP(int) #if !defined(QT_GUI) bool AppInit(int argc, char* argv[]) { + boost::thread_group threadGroup; bool fRet = false; try { @@ -185,7 +196,7 @@ bool AppInit(int argc, char* argv[]) exit(ret); } - fRet = AppInit2(); + fRet = AppInit2(threadGroup); } catch (std::exception& e) { PrintExceptionContinue(&e, "AppInit()"); @@ -193,7 +204,11 @@ bool AppInit(int argc, char* argv[]) PrintExceptionContinue(NULL, "AppInit()"); } if (!fRet) + { Shutdown(NULL); + threadGroup.interrupt_all(); + threadGroup.join_all(); + } return fRet; } @@ -405,7 +420,7 @@ void ThreadImport(void *data) { /** Initialize bitcoin. * @pre Parameters should be parsed and config file should be read. */ -bool AppInit2() +bool AppInit2(boost::thread_group& threadGroup) { // ********************************************************* Step 1: setup #ifdef _MSC_VER @@ -449,6 +464,8 @@ bool AppInit2() sigaction(SIGHUP, &sa_hup, NULL); #endif + threadGroup.create_thread(boost::bind(&DetectShutdownThread, &threadGroup)); + // ********************************************************* Step 2: parameter interactions fTestNet = GetBoolArg("-testnet"); |