aboutsummaryrefslogtreecommitdiff
path: root/src/db.h
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@exmulti.com>2012-05-13 21:37:39 -0400
committerJeff Garzik <jgarzik@redhat.com>2012-05-19 20:43:19 -0400
commitcd9696fc97fc06831c1edede62a063028f2afe75 (patch)
tree8a1ce2483296e0370a2986bb781c4f55d4f01e64 /src/db.h
parentb52a27053850590e0ac8f1431a9aad50b7beffee (diff)
downloadbitcoin-cd9696fc97fc06831c1edede62a063028f2afe75.tar.xz
Encapsulate BDB environment inside new CDBEnv class
Cleans up and organizes several scattered functions and variables related to the BDB env. Class CDBInit() existed to provide a guaranteed-via-C++-destructor cleanup of the db environment. A formal CDBEnv class provides all of this inside a single wrapper.
Diffstat (limited to 'src/db.h')
-rw-r--r--src/db.h30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/db.h b/src/db.h
index 0ff06e40a8..e2983e0787 100644
--- a/src/db.h
+++ b/src/db.h
@@ -25,14 +25,36 @@ class CWallet;
class CWalletTx;
extern unsigned int nWalletDBUpdated;
-extern bool fDetachDB;
-extern DbEnv dbenv;
-extern void DBFlush(bool fShutdown);
void ThreadFlushWalletDB(void* parg);
bool BackupWallet(const CWallet& wallet, const std::string& strDest);
+class CDBEnv
+{
+private:
+ bool fDetachDB;
+ bool fDbEnvInit;
+ boost::filesystem::path pathEnv;
+
+ void EnvShutdown();
+
+public:
+ mutable CCriticalSection cs_db;
+ DbEnv dbenv;
+
+ CDBEnv();
+ ~CDBEnv();
+ bool Open(boost::filesystem::path pathEnv_);
+ void Close();
+ void Flush(bool fShutdown);
+ void CheckpointLSN(std::string strFile);
+ void SetDetach(bool fDetachDB_) { fDetachDB = fDetachDB_; }
+};
+
+extern CDBEnv bitdb;
+
+
/** RAII class that provides access to a Berkeley database */
class CDB
{
@@ -216,7 +238,7 @@ public:
if (!pdb)
return false;
DbTxn* ptxn = NULL;
- int ret = dbenv.txn_begin(GetTxn(), &ptxn, DB_TXN_WRITE_NOSYNC);
+ int ret = bitdb.dbenv.txn_begin(GetTxn(), &ptxn, DB_TXN_WRITE_NOSYNC);
if (!ptxn || ret != 0)
return false;
vTxn.push_back(ptxn);