extern CDBEnv bitdb;
| 355 | |
| 356 | // extern CDBEnv bitdb; |
| 357 | void 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 | |
| 410 | void ThreadRelayTx(CWallet* pWallet) { |
| 411 | RenameThread("coin-relaytx"); |
nothing calls this directly
no test coverage detected