mdbx: добавление mdbx_txn_release_all_cursors() в API.

This commit is contained in:
Леонид Юрьев (Leonid Yuriev)
2023-10-13 22:38:51 +03:00
parent d28a397b2d
commit 4d3f7e1edc
3 changed files with 63 additions and 0 deletions

View File

@@ -19019,6 +19019,32 @@ void mdbx_cursor_close(MDBX_cursor *mc) {
}
}
int mdbx_txn_release_all_cursors(const MDBX_txn *txn, bool unbind) {
int rc = check_txn(txn, MDBX_TXN_FINISHED | MDBX_TXN_HAS_CHILD);
if (likely(rc == MDBX_SUCCESS)) {
for (size_t i = FREE_DBI; i < txn->mt_numdbs; ++i) {
while (txn->mt_cursors[i]) {
MDBX_cursor *mc = txn->mt_cursors[i];
ENSURE(NULL, mc->mc_signature == MDBX_MC_LIVE &&
(mc->mc_flags & C_UNTRACK) && !mc->mc_backup);
rc = likely(rc < INT_MAX) ? rc + 1 : rc;
txn->mt_cursors[i] = mc->mc_next;
if (unbind) {
mc->mc_signature = MDBX_MC_READY4CLOSE;
mc->mc_flags = 0;
} else {
mc->mc_signature = 0;
mc->mc_next = mc;
osal_free(mc);
}
}
}
} else {
eASSERT(nullptr, rc < 0);
}
return rc;
}
MDBX_txn *mdbx_cursor_txn(const MDBX_cursor *mc) {
if (unlikely(!mc || mc->mc_signature != MDBX_MC_LIVE))
return NULL;