diff options
author | Andrew Chow <achow101-github@achow101.com> | 2020-06-19 20:51:07 -0400 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2020-07-14 11:07:16 -0400 |
commit | 71d28e7cdca1c8553531bb3a4725d7916363ec5c (patch) | |
tree | 297581efdd39252282410442280cddcc61aa03e5 /src/wallet/bdb.cpp | |
parent | 27b27663849932971eb5deadb1f19234b9cd97ea (diff) | |
download | bitcoin-71d28e7cdca1c8553531bb3a4725d7916363ec5c.tar.xz |
walletdb: Introduce AddRef and RemoveRef functions
Refactor mapFileUseCount increment and decrement to separate functions
AddRef and RemoveRef
Diffstat (limited to 'src/wallet/bdb.cpp')
-rw-r--r-- | src/wallet/bdb.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/wallet/bdb.cpp b/src/wallet/bdb.cpp index 0989dc21c3..8ca4991f04 100644 --- a/src/wallet/bdb.cpp +++ b/src/wallet/bdb.cpp @@ -334,7 +334,7 @@ BerkeleyDatabase::~BerkeleyDatabase() } } -BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const char* pszMode, bool fFlushOnCloseIn) : pdb(nullptr), activeTxn(nullptr), m_cursor(nullptr) +BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const char* pszMode, bool fFlushOnCloseIn) : pdb(nullptr), activeTxn(nullptr), m_cursor(nullptr), m_database(database) { fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w')); fFlushOnClose = fFlushOnCloseIn; @@ -408,7 +408,7 @@ BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const char* pszMode, bo fReadOnly = fTmp; } } - ++env->mapFileUseCount[strFilename]; + database.AddRef(); strFile = strFilename; } } @@ -446,11 +446,7 @@ void BerkeleyBatch::Close() if (fFlushOnClose) Flush(); - { - LOCK(cs_db); - --env->mapFileUseCount[strFile]; - } - env->m_db_in_use.notify_all(); + m_database.RemoveRef(); } void BerkeleyEnvironment::CloseDb(const std::string& strFile) @@ -846,6 +842,21 @@ bool BerkeleyBatch::HasKey(CDataStream&& key) return ret == 0; } +void BerkeleyDatabase::AddRef() +{ + LOCK(cs_db); + ++env->mapFileUseCount[strFile]; +} + +void BerkeleyDatabase::RemoveRef() +{ + { + LOCK(cs_db); + --env->mapFileUseCount[strFile]; + } + env->m_db_in_use.notify_all(); +} + std::unique_ptr<BerkeleyBatch> BerkeleyDatabase::MakeBatch(const char* mode, bool flush_on_close) { return MakeUnique<BerkeleyBatch>(*this, mode, flush_on_close); |