From 7a5b7535bf3b987c5e2157f25c8b3246033d952e Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 22 Oct 2012 22:45:26 +0200 Subject: Move ThreadImport to init.cpp --- src/init.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index 8151fb2a86..6fa8586426 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -310,6 +310,50 @@ std::string HelpMessage() } +struct CImportingNow +{ + CImportingNow() { + assert(fImporting == false); + fImporting = true; + } + + ~CImportingNow() { + assert(fImporting == true); + fImporting = false; + } +}; + +void ThreadImport(void *data) { + std::vector *vFiles = reinterpret_cast*>(data); + + RenameThread("bitcoin-loadblk"); + + CImportingNow imp; + vnThreadsRunning[THREAD_IMPORT]++; + + // -loadblock= + BOOST_FOREACH(boost::filesystem::path &path, *vFiles) { + FILE *file = fopen(path.string().c_str(), "rb"); + if (file) + LoadExternalBlockFile(file); + } + + // hardcoded $DATADIR/bootstrap.dat + filesystem::path pathBootstrap = GetDataDir() / "bootstrap.dat"; + if (filesystem::exists(pathBootstrap)) { + FILE *file = fopen(pathBootstrap.string().c_str(), "rb"); + if (file) { + filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old"; + LoadExternalBlockFile(file); + RenameOver(pathBootstrap, pathBootstrapOld); + } + } + + delete vFiles; + + vnThreadsRunning[THREAD_IMPORT]--; +} + /** Initialize bitcoin. * @pre Parameters should be parsed and config file should be read. */ -- cgit v1.2.3