aboutsummaryrefslogtreecommitdiff
path: root/src/db.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/db.cpp')
-rw-r--r--src/db.cpp24
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;