@@ -334,7 +334,7 @@ BerkeleyDatabase::~BerkeleyDatabase()
334
334
}
335
335
}
336
336
337
- BerkeleyBatch::BerkeleyBatch (BerkeleyDatabase& database, const char * pszMode, bool fFlushOnCloseIn ) : pdb(nullptr ), activeTxn(nullptr ), m_cursor(nullptr )
337
+ BerkeleyBatch::BerkeleyBatch (BerkeleyDatabase& database, const char * pszMode, bool fFlushOnCloseIn ) : pdb(nullptr ), activeTxn(nullptr ), m_cursor(nullptr ), m_database(database)
338
338
{
339
339
fReadOnly = (!strchr (pszMode, ' +' ) && !strchr (pszMode, ' w' ));
340
340
fFlushOnClose = fFlushOnCloseIn ;
@@ -408,7 +408,7 @@ BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const char* pszMode, bo
408
408
fReadOnly = fTmp ;
409
409
}
410
410
}
411
- ++env-> mapFileUseCount [strFilename] ;
411
+ database. AddRef () ;
412
412
strFile = strFilename;
413
413
}
414
414
}
@@ -446,11 +446,7 @@ void BerkeleyBatch::Close()
446
446
if (fFlushOnClose )
447
447
Flush ();
448
448
449
- {
450
- LOCK (cs_db);
451
- --env->mapFileUseCount [strFile];
452
- }
453
- env->m_db_in_use .notify_all ();
449
+ m_database.RemoveRef ();
454
450
}
455
451
456
452
void BerkeleyEnvironment::CloseDb (const std::string& strFile)
@@ -846,6 +842,21 @@ bool BerkeleyBatch::HasKey(CDataStream&& key)
846
842
return ret == 0 ;
847
843
}
848
844
845
+ void BerkeleyDatabase::AddRef ()
846
+ {
847
+ LOCK (cs_db);
848
+ ++env->mapFileUseCount [strFile];
849
+ }
850
+
851
+ void BerkeleyDatabase::RemoveRef ()
852
+ {
853
+ {
854
+ LOCK (cs_db);
855
+ --env->mapFileUseCount [strFile];
856
+ }
857
+ env->m_db_in_use .notify_all ();
858
+ }
859
+
849
860
std::unique_ptr<BerkeleyBatch> BerkeleyDatabase::MakeBatch (const char * mode, bool flush_on_close)
850
861
{
851
862
return MakeUnique<BerkeleyBatch>(*this , mode, flush_on_close);
0 commit comments