mirror of
https://github.com/isar/libmdbx.git
synced 2025-06-23 01:42:36 +08:00
mdbx: изоляция txl-списков от кода PNL.
This commit is contained in:
parent
86890b4756
commit
a9d910e8fd
26
src/txl.c
26
src/txl.c
@ -38,8 +38,8 @@ void txl_free(txl_t txl) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int txl_reserve(txl_t __restrict *__restrict ptxl, const size_t wanna) {
|
static int txl_reserve(txl_t __restrict *__restrict ptxl, const size_t wanna) {
|
||||||
const size_t allocated = (size_t)MDBX_PNL_ALLOCLEN(*ptxl);
|
const size_t allocated = txl_alloclen(*ptxl);
|
||||||
assert(MDBX_PNL_GETSIZE(*ptxl) <= txl_max && MDBX_PNL_ALLOCLEN(*ptxl) >= MDBX_PNL_GETSIZE(*ptxl));
|
assert(txl_size(*ptxl) <= txl_max && txl_alloclen(*ptxl) >= txl_size(*ptxl));
|
||||||
if (likely(allocated >= wanna))
|
if (likely(allocated >= wanna))
|
||||||
return MDBX_SUCCESS;
|
return MDBX_SUCCESS;
|
||||||
|
|
||||||
@ -64,34 +64,34 @@ static int txl_reserve(txl_t __restrict *__restrict ptxl, const size_t wanna) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline int __must_check_result txl_need(txl_t __restrict *__restrict ptxl, size_t num) {
|
static inline int __must_check_result txl_need(txl_t __restrict *__restrict ptxl, size_t num) {
|
||||||
assert(MDBX_PNL_GETSIZE(*ptxl) <= txl_max && MDBX_PNL_ALLOCLEN(*ptxl) >= MDBX_PNL_GETSIZE(*ptxl));
|
assert(txl_size(*ptxl) <= txl_max && txl_alloclen(*ptxl) >= txl_size(*ptxl));
|
||||||
assert(num <= PAGELIST_LIMIT);
|
assert(num <= PAGELIST_LIMIT);
|
||||||
const size_t wanna = (size_t)MDBX_PNL_GETSIZE(*ptxl) + num;
|
const size_t wanna = txl_size(*ptxl) + num;
|
||||||
return likely(MDBX_PNL_ALLOCLEN(*ptxl) >= wanna) ? MDBX_SUCCESS : txl_reserve(ptxl, wanna);
|
return likely(txl_alloclen(*ptxl) >= wanna) ? MDBX_SUCCESS : txl_reserve(ptxl, wanna);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void txl_xappend(txl_t __restrict txl, txnid_t id) {
|
static inline void txl_append_prereserved(txl_t __restrict txl, txnid_t id) {
|
||||||
assert(MDBX_PNL_GETSIZE(txl) < MDBX_PNL_ALLOCLEN(txl));
|
assert(txl_size(txl) < txl_alloclen(txl));
|
||||||
txl[0] += 1;
|
size_t end = txl[0] += 1;
|
||||||
MDBX_PNL_LAST(txl) = id;
|
txl[end] = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TXNID_SORT_CMP(first, last) ((first) > (last))
|
#define TXNID_SORT_CMP(first, last) ((first) > (last))
|
||||||
SORT_IMPL(txnid_sort, false, txnid_t, TXNID_SORT_CMP)
|
SORT_IMPL(txnid_sort, false, txnid_t, TXNID_SORT_CMP)
|
||||||
void txl_sort(txl_t txl) { txnid_sort(MDBX_PNL_BEGIN(txl), MDBX_PNL_END(txl)); }
|
void txl_sort(txl_t txl) { txnid_sort(txl + 1, txl + txl_size(txl) + 1); }
|
||||||
|
|
||||||
int __must_check_result txl_append(txl_t __restrict *ptxl, txnid_t id) {
|
int __must_check_result txl_append(txl_t __restrict *ptxl, txnid_t id) {
|
||||||
if (unlikely(MDBX_PNL_GETSIZE(*ptxl) == MDBX_PNL_ALLOCLEN(*ptxl))) {
|
if (unlikely(txl_size(*ptxl) == txl_alloclen(*ptxl))) {
|
||||||
int rc = txl_need(ptxl, txl_granulate);
|
int rc = txl_need(ptxl, txl_granulate);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
txl_xappend(*ptxl, id);
|
txl_append_prereserved(*ptxl, id);
|
||||||
return MDBX_SUCCESS;
|
return MDBX_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
__hot bool txl_contain(const txl_t txl, txnid_t id) {
|
__hot bool txl_contain(const txl_t txl, txnid_t id) {
|
||||||
const size_t len = MDBX_PNL_GETSIZE(txl);
|
const size_t len = txl_size(txl);
|
||||||
for (size_t i = 1; i <= len; ++i)
|
for (size_t i = 1; i <= len; ++i)
|
||||||
if (txl[i] == id)
|
if (txl[i] == id)
|
||||||
return true;
|
return true;
|
||||||
|
@ -24,3 +24,7 @@ MDBX_MAYBE_UNUSED MDBX_INTERNAL int __must_check_result txl_append(txl_t __restr
|
|||||||
MDBX_MAYBE_UNUSED MDBX_INTERNAL void txl_sort(txl_t txl);
|
MDBX_MAYBE_UNUSED MDBX_INTERNAL void txl_sort(txl_t txl);
|
||||||
|
|
||||||
MDBX_MAYBE_UNUSED MDBX_INTERNAL bool txl_contain(const txl_t txl, txnid_t id);
|
MDBX_MAYBE_UNUSED MDBX_INTERNAL bool txl_contain(const txl_t txl, txnid_t id);
|
||||||
|
|
||||||
|
static inline size_t txl_alloclen(const_txl_t txl) { return txl[-1]; }
|
||||||
|
|
||||||
|
static inline size_t txl_size(const_txl_t txl) { return txl[0]; }
|
||||||
|
@ -183,7 +183,7 @@ static bool stochastic_pass(const unsigned start, const unsigned width, const un
|
|||||||
|
|
||||||
txnid_t lowest = UINT_MAX;
|
txnid_t lowest = UINT_MAX;
|
||||||
txnid_t highest = 0;
|
txnid_t highest = 0;
|
||||||
while (MDBX_PNL_GETSIZE(l) < n) {
|
while (txl_size(l) < n) {
|
||||||
txnid_t id = (txnid_t)(prng() % width + start);
|
txnid_t id = (txnid_t)(prng() % width + start);
|
||||||
if (id < MIN_TXNID || id >= INVALID_TXNID)
|
if (id < MIN_TXNID || id >= INVALID_TXNID)
|
||||||
continue;
|
continue;
|
||||||
@ -227,7 +227,7 @@ static bool stochastic_pass(const unsigned start, const unsigned width, const un
|
|||||||
|
|
||||||
txl_sort(l);
|
txl_sort(l);
|
||||||
CHECK_EQ(rkl_len(&k), n);
|
CHECK_EQ(rkl_len(&k), n);
|
||||||
CHECK_EQ(MDBX_PNL_GETSIZE(l), n);
|
CHECK_EQ(txl_size(l), n);
|
||||||
|
|
||||||
f = rkl_iterator(&k, false);
|
f = rkl_iterator(&k, false);
|
||||||
r = rkl_iterator(&k, true);
|
r = rkl_iterator(&k, true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user