From 1b43bf0d3ae7b1fcde0c0e20c23c341540f4c8d2 Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Thu, 7 Mar 2013 14:25:21 -0500 Subject: Rename util.h Sleep --> MilliSleep Two reasons for this change: 1. Need to always use boost::thread's sleep, even on Windows, so the sleeps can be interrupted (prior code used Windows' built-in Sleep). 2. I always forgot what units the old Sleep took. --- src/walletdb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/walletdb.cpp') diff --git a/src/walletdb.cpp b/src/walletdb.cpp index fe9bce21e..96bc05b11 100644 --- a/src/walletdb.cpp +++ b/src/walletdb.cpp @@ -500,7 +500,7 @@ void ThreadFlushWalletDB(void* parg) int64 nLastWalletUpdate = GetTime(); while (!fShutdown) { - Sleep(500); + MilliSleep(500); if (nLastSeen != nWalletDBUpdated) { @@ -579,7 +579,7 @@ bool BackupWallet(const CWallet& wallet, const string& strDest) } } } - Sleep(100); + MilliSleep(100); } return false; } -- cgit v1.2.3 From b31499ec72edd1554d4612d1b54808fce0360e14 Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Sat, 9 Mar 2013 12:02:57 -0500 Subject: Clean up shutdown process --- src/walletdb.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/walletdb.cpp') diff --git a/src/walletdb.cpp b/src/walletdb.cpp index 96bc05b11..abaf5a0fd 100644 --- a/src/walletdb.cpp +++ b/src/walletdb.cpp @@ -451,8 +451,10 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) } pcursor->close(); } - catch (...) - { + catch (boost::thread_interrupted) { + throw; + } + catch (...) { result = DB_CORRUPT; } @@ -482,12 +484,11 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) return result; } -void ThreadFlushWalletDB(void* parg) +void ThreadFlushWalletDB(const string& strFile) { // Make this thread recognisable as the wallet flushing thread RenameThread("bitcoin-wallet"); - const string& strFile = ((const string*)parg)[0]; static bool fOneThread; if (fOneThread) return; @@ -498,7 +499,7 @@ void ThreadFlushWalletDB(void* parg) unsigned int nLastSeen = nWalletDBUpdated; unsigned int nLastFlushed = nWalletDBUpdated; int64 nLastWalletUpdate = GetTime(); - while (!fShutdown) + while (true) { MilliSleep(500); @@ -522,8 +523,9 @@ void ThreadFlushWalletDB(void* parg) mi++; } - if (nRefCount == 0 && !fShutdown) + if (nRefCount == 0) { + boost::this_thread::interruption_point(); map::iterator mi = bitdb.mapFileUseCount.find(strFile); if (mi != bitdb.mapFileUseCount.end()) { @@ -548,7 +550,7 @@ bool BackupWallet(const CWallet& wallet, const string& strDest) { if (!wallet.fFileBacked) return false; - while (!fShutdown) + while (true) { { LOCK(bitdb.cs_db); -- cgit v1.2.3