@@ -903,34 +903,9 @@ void ThreadFlushWalletDB()
903903 }
904904
905905 if (nLastFlushed != CWalletDB::GetUpdateCounter () && GetTime () - nLastWalletUpdate >= 2 ) {
906- TRY_LOCK (bitdb.cs_db , lockDb);
907- if (lockDb) {
908- // Don't do this if any databases are in use
909- int nRefCount = 0 ;
910- std::map<std::string, int >::iterator mi = bitdb.mapFileUseCount .begin ();
911- while (mi != bitdb.mapFileUseCount .end ()) {
912- nRefCount += (*mi).second ;
913- mi++;
914- }
915-
916- if (nRefCount == 0 ) {
917- boost::this_thread::interruption_point ();
918- const std::string& strFile = pwalletMain->strWalletFile ;
919- std::map<std::string, int >::iterator _mi = bitdb.mapFileUseCount .find (strFile);
920- if (_mi != bitdb.mapFileUseCount .end ()) {
921- LogPrint (BCLog::DB, " Flushing %s\n " , strFile);
922- nLastFlushed = CWalletDB::GetUpdateCounter ();
923- int64_t nStart = GetTimeMillis ();
924-
925- // Flush wallet file so it's self contained
926- bitdb.CloseDb (strFile);
927- bitdb.CheckpointLSN (strFile);
928-
929- bitdb.mapFileUseCount .erase (_mi++);
930- LogPrint (BCLog::DB, " Flushed %s %dms\n " , strFile, GetTimeMillis () - nStart);
931- }
932- }
933- }
906+ const std::string& strFile = pwalletMain->strWalletFile ;
907+ if (CDB::PeriodicFlush (strFile))
908+ nLastFlushed = CWalletDB::GetUpdateCounter ();
934909 }
935910 }
936911}
0 commit comments