diff options
author | Jeff Garzik <jgarzik@exmulti.com> | 2012-05-18 02:49:50 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@redhat.com> | 2012-05-19 20:46:52 -0400 |
commit | ffe8b77a617efd802a9d4ba7e42b163fbd9a250b (patch) | |
tree | 38bef9570c2b71b299cd5d54bfb6f178ce59cf32 /src/db.cpp | |
parent | 94e34fa0adb818baacdcb6408f0a92e07f3ce7df (diff) |
Further CDBEnv encapsulation work.
Diffstat (limited to 'src/db.cpp')
-rw-r--r-- | src/db.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/db.cpp b/src/db.cpp index 08b6614181..f0addda918 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -27,8 +27,6 @@ unsigned int nWalletDBUpdated; // CDBEnv bitdb; -map<string, int> mapFileUseCount; -static map<string, Db*> mapDb; void CDBEnv::EnvShutdown() { @@ -129,8 +127,8 @@ CDB::CDB(const char *pszFile, const char* pszMode) : throw runtime_error("env open failed"); strFile = pszFile; - ++mapFileUseCount[strFile]; - pdb = mapDb[strFile]; + ++bitdb.mapFileUseCount[strFile]; + pdb = bitdb.mapDb[strFile]; if (pdb == NULL) { pdb = new Db(&bitdb.dbenv, 0); @@ -148,7 +146,7 @@ CDB::CDB(const char *pszFile, const char* pszMode) : pdb = NULL; { LOCK(bitdb.cs_db); - --mapFileUseCount[strFile]; + --bitdb.mapFileUseCount[strFile]; } strFile = ""; throw runtime_error(strprintf("CDB() : can't open database file %s, error %d", pszFile, ret)); @@ -162,7 +160,7 @@ CDB::CDB(const char *pszFile, const char* pszMode) : fReadOnly = fTmp; } - mapDb[strFile] = pdb; + bitdb.mapDb[strFile] = pdb; } } } @@ -189,14 +187,14 @@ void CDB::Close() { LOCK(bitdb.cs_db); - --mapFileUseCount[strFile]; + --bitdb.mapFileUseCount[strFile]; } } -void CloseDb(const string& strFile) +void CDBEnv::CloseDb(const string& strFile) { { - LOCK(bitdb.cs_db); + LOCK(cs_db); if (mapDb[strFile] != NULL) { // Close the database handle @@ -214,12 +212,12 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip) { { LOCK(bitdb.cs_db); - if (!mapFileUseCount.count(strFile) || mapFileUseCount[strFile] == 0) + if (!bitdb.mapFileUseCount.count(strFile) || bitdb.mapFileUseCount[strFile] == 0) { // Flush log data to the dat file - CloseDb(strFile); + bitdb.CloseDb(strFile); bitdb.CheckpointLSN(strFile); - mapFileUseCount.erase(strFile); + bitdb.mapFileUseCount.erase(strFile); bool fSuccess = true; printf("Rewriting %s...\n", strFile.c_str()); @@ -276,7 +274,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip) if (fSuccess) { db.Close(); - CloseDb(strFile); + bitdb.CloseDb(strFile); if (pdbCopy->close(0)) fSuccess = false; delete pdbCopy; |