MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / ThreadFlushWalletDB

Function ThreadFlushWalletDB

src/wallet/walletdb.cpp:357–408  ·  view source on GitHub ↗

extern CDBEnv bitdb;

Source from the content-addressed store, hash-verified

355
356// extern CDBEnv bitdb;
357void ThreadFlushWalletDB(const string& strFile) {
358 // Make this thread recognisable as the wallet flushing thread
359 RenameThread("coin-wallet");
360 static bool fOneThread;
361 if (fOneThread)
362 return;
363 fOneThread = true;
364 if (!SysCfg().GetBoolArg("-flushwallet", true))
365 return;
366
367 uint32_t nLastSeen = CWalletDB::nWalletDBUpdated;
368 uint32_t nLastFlushed = CWalletDB::nWalletDBUpdated;
369 int64_t nLastWalletUpdate = GetTime();
370 while (true) {
371 MilliSleep(500);
372
373 if (nLastSeen != CWalletDB::nWalletDBUpdated) {
374 nLastSeen = CWalletDB::nWalletDBUpdated;
375 nLastWalletUpdate = GetTime();
376 }
377
378 if (nLastFlushed != CWalletDB::nWalletDBUpdated && GetTime() - nLastWalletUpdate >= 2) {
379 TRY_LOCK(bitdb.cs_db, lockDb);
380 if (lockDb) {
381 // Don't do this if any databases are in use
382 int32_t nRefCount = 0;
383 map<string, int32_t>::iterator mi = bitdb.mapFileUseCount.begin();
384 while (mi != bitdb.mapFileUseCount.end()) {
385 nRefCount += (*mi).second;
386 mi++;
387 }
388
389 if (nRefCount == 0) {
390 boost::this_thread::interruption_point();
391 map<string, int32_t>::iterator mi = bitdb.mapFileUseCount.find(strFile);
392 if (mi != bitdb.mapFileUseCount.end()) {
393 LogPrint(BCLog::CDB, "Flushing wallet.dat\n");
394 nLastFlushed = CWalletDB::nWalletDBUpdated;
395 int64_t nStart = GetTimeMillis();
396
397 // Flush wallet.dat so it's self contained
398 bitdb.CloseDb(strFile);
399 bitdb.CheckpointLSN(strFile);
400
401 bitdb.mapFileUseCount.erase(mi++);
402 LogPrint(BCLog::CDB, "Flushed wallet.dat %dms\n", GetTimeMillis() - nStart);
403 }
404 }
405 }
406 }
407 }
408}
409
410void ThreadRelayTx(CWallet* pWallet) {
411 RenameThread("coin-relaytx");

Callers

nothing calls this directly

Calls 11

RenameThreadFunction · 0.85
GetTimeFunction · 0.85
MilliSleepFunction · 0.85
GetBoolArgMethod · 0.80
CloseDbMethod · 0.80
CheckpointLSNMethod · 0.80
GetTimeMillisFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
findMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected