mdbx: extract mdbx_get_sysraminfo().

Change-Id: I8821009572d275a3b5d2d8729f605b115a80e50a
This commit is contained in:
Leonid Yuriev
2021-04-07 01:45:14 +03:00
parent 0f76002dde
commit 024ccf6826
4 changed files with 152 additions and 112 deletions

View File

@@ -1389,6 +1389,23 @@ ceil_powerof2(size_t value, size_t granularity) {
return floor_powerof2(value + granularity - 1, granularity);
}
MDBX_NOTHROW_CONST_FUNCTION static __maybe_unused unsigned log2n(size_t value) {
assert(value > 0 && value < INT32_MAX && is_powerof2(value));
assert((value & -(int32_t)value) == value);
#if __GNUC_PREREQ(4, 1) || __has_builtin(__builtin_ctzl)
return __builtin_ctzl(value);
#elif defined(_MSC_VER)
unsigned long index;
_BitScanForward(&index, (unsigned long)value);
return index;
#else
static const uint8_t debruijn_ctz32[32] = {
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
return debruijn_ctz32[(uint32_t)(value * 0x077CB531u) >> 27];
#endif
}
/* Only a subset of the mdbx_env flags can be changed
* at runtime. Changing other flags requires closing the
* environment and re-opening it with the new flags. */