aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2016-03-16 14:46:17 +0200
committerRiccardo Spagni <ric@spagni.net>2016-03-16 14:46:17 +0200
commit33bdba5cdd377d8129a6951d6efdd9271c79b346 (patch)
tree6086237f090ba18c446dfa2608b7bc954b57acfa /src
parentMerge pull request #727 (diff)
parentAdd destructor for readtxns (diff)
downloadmonero-33bdba5cdd377d8129a6951d6efdd9271c79b346.tar.xz
Merge pull request #729
a74348e Add destructor for readtxns (Howard Chu)
Diffstat (limited to 'src')
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp27
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.h4
2 files changed, 21 insertions, 10 deletions
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index d2939bf96..9ae7b404b 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -228,17 +228,24 @@ mdb_threadinfo::~mdb_threadinfo()
mdb_txn_abort(m_ti_rtxn);
}
-mdb_txn_safe::mdb_txn_safe() : m_txn(NULL)
+mdb_txn_safe::mdb_txn_safe(const bool check) : m_txn(NULL), m_tinfo(NULL), m_check(check)
{
- while (creation_gate.test_and_set());
- num_active_txns++;
- creation_gate.clear();
+ if (check)
+ {
+ while (creation_gate.test_and_set());
+ num_active_txns++;
+ creation_gate.clear();
+ }
}
mdb_txn_safe::~mdb_txn_safe()
{
LOG_PRINT_L3("mdb_txn_safe: destructor");
- if (m_txn != nullptr)
+ if (m_tinfo != nullptr)
+ {
+ mdb_txn_reset(m_tinfo->m_ti_rtxn);
+ memset(&m_tinfo->m_ti_rflags, 0, sizeof(m_tinfo->m_ti_rflags));
+ } else if (m_txn != nullptr)
{
if (m_batch_txn) // this is a batch txn and should have been handled before this point for safety
{
@@ -256,7 +263,8 @@ mdb_txn_safe::~mdb_txn_safe()
}
mdb_txn_abort(m_txn);
}
- num_active_txns--;
+ if (m_check)
+ num_active_txns--;
}
void mdb_txn_safe::commit(std::string message)
@@ -1303,9 +1311,10 @@ void BlockchainLMDB::unlock()
#define TXN_PREFIX_RDONLY() \
MDB_txn *m_txn; \
mdb_txn_cursors *m_cursors; \
- bool my_rtxn = block_rtxn_start(&m_txn, &m_cursors);
-#define TXN_POSTFIX_RDONLY() \
- if (my_rtxn) block_rtxn_stop()
+ bool my_rtxn = block_rtxn_start(&m_txn, &m_cursors); \
+ mdb_txn_safe auto_txn(my_rtxn); \
+ if (my_rtxn) auto_txn.m_tinfo = m_tinfo.get()
+#define TXN_POSTFIX_RDONLY()
#define TXN_POSTFIX_SUCCESS() \
do { \
diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h
index 718ee1058..a3f32ffaa 100644
--- a/src/blockchain_db/lmdb/db_lmdb.h
+++ b/src/blockchain_db/lmdb/db_lmdb.h
@@ -115,7 +115,7 @@ typedef struct mdb_threadinfo
struct mdb_txn_safe
{
- mdb_txn_safe();
+ mdb_txn_safe(const bool check=true);
~mdb_txn_safe();
void commit(std::string message = "");
@@ -142,8 +142,10 @@ struct mdb_txn_safe
static void wait_no_active_txns();
static void allow_new_txns();
+ mdb_threadinfo* m_tinfo;
MDB_txn* m_txn;
bool m_batch_txn = false;
+ bool m_check;
static std::atomic<uint64_t> num_active_txns;
// could use a mutex here, but this should be sufficient.