mdbx: fix mdbx_canary_put().

This commit is contained in:
Leo Yuriev 2017-04-17 19:35:36 +03:00
parent a4a542c3b5
commit dfc3020426
2 changed files with 8 additions and 1 deletions

2
mdbx.h
View File

@ -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);

View File

@ -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;
}