mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 00:24:13 +08:00
mdbx: fix mdbx_canary_put().
This commit is contained in:
parent
a4a542c3b5
commit
dfc3020426
2
mdbx.h
2
mdbx.h
@ -1725,7 +1725,7 @@ typedef int MDBX_pgvisitor_func(size_t pgno, unsigned pgnumber, void *ctx,
|
||||
LIBMDBX_API int mdbx_env_pgwalk(MDB_txn *txn, MDBX_pgvisitor_func *visitor,
|
||||
void *ctx);
|
||||
|
||||
typedef struct mdbx_canary { size_t x, y, z, v; } mdbx_canary;
|
||||
typedef struct mdbx_canary { uint64_t x, y, z, v; } mdbx_canary;
|
||||
|
||||
LIBMDBX_API int mdbx_canary_put(MDB_txn *txn, const mdbx_canary *canary);
|
||||
LIBMDBX_API size_t mdbx_canary_get(MDB_txn *txn, mdbx_canary *canary);
|
||||
|
@ -9841,15 +9841,22 @@ int mdbx_canary_put(MDB_txn *txn, const mdbx_canary *canary) {
|
||||
if (unlikely(txn->mt_signature != MDBX_MT_SIGNATURE))
|
||||
return MDBX_EBADSIGN;
|
||||
|
||||
if (unlikely(txn->mt_flags & MDB_TXN_BLOCKED))
|
||||
return MDB_BAD_TXN;
|
||||
|
||||
if (unlikely(F_ISSET(txn->mt_flags, MDB_TXN_RDONLY)))
|
||||
return EACCES;
|
||||
|
||||
if (likely(canary)) {
|
||||
if (txn->mt_canary.x == canary->x && txn->mt_canary.y == canary->y &&
|
||||
txn->mt_canary.z == canary->z && txn->mt_canary.v == canary->v)
|
||||
return MDB_SUCCESS;
|
||||
txn->mt_canary.x = canary->x;
|
||||
txn->mt_canary.y = canary->y;
|
||||
txn->mt_canary.z = canary->z;
|
||||
}
|
||||
txn->mt_canary.v = txn->mt_txnid;
|
||||
txn->mt_flags |= MDB_TXN_DIRTY;
|
||||
|
||||
return MDB_SUCCESS;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user