mirror of
https://github.com/isar/libmdbx.git
synced 2025-10-06 01:02:20 +08:00
mdbx: using enum
instead of #define for flags/modes.
Resolve https://github.com/erthink/libmdbx/issues/108 Change-Id: I45897300375d2b5b9361aaba81dadcf9801fe3cf
This commit is contained in:
22
src/core.c
22
src/core.c
@@ -9254,7 +9254,7 @@ int __cold mdbx_env_set_mapsize(MDBX_env *env, size_t size) {
|
||||
}
|
||||
|
||||
int __cold mdbx_env_set_maxdbs(MDBX_env *env, MDBX_dbi dbs) {
|
||||
if (unlikely(dbs > MAX_DBI))
|
||||
if (unlikely(dbs > MDBX_MAX_DBI))
|
||||
return MDBX_EINVAL;
|
||||
|
||||
if (unlikely(!env))
|
||||
@@ -10028,26 +10028,6 @@ __cold int mdbx_is_readahead_reasonable(size_t volume, intptr_t redundancy) {
|
||||
: MDBX_RESULT_TRUE;
|
||||
}
|
||||
|
||||
/* 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. */
|
||||
#define ENV_CHANGEABLE_FLAGS \
|
||||
(MDBX_SAFE_NOSYNC | MDBX_NOMETASYNC | MDBX_MAPASYNC | MDBX_NOMEMINIT | \
|
||||
MDBX_COALESCE | MDBX_PAGEPERTURB | MDBX_ACCEDE)
|
||||
#define ENV_CHANGELESS_FLAGS \
|
||||
(MDBX_NOSUBDIR | MDBX_RDONLY | MDBX_WRITEMAP | MDBX_NOTLS | MDBX_NORDAHEAD | \
|
||||
MDBX_LIFORECLAIM | MDBX_EXCLUSIVE)
|
||||
#define ENV_USABLE_FLAGS (ENV_CHANGEABLE_FLAGS | ENV_CHANGELESS_FLAGS)
|
||||
|
||||
#if ENV_INTERNAL_FLAGS & ENV_USABLE_FLAGS
|
||||
#error "Oops, some flags overlapped or wrong"
|
||||
#endif
|
||||
|
||||
#if (MDBX_ACCEDE | MDBX_CREATE) != ((DB_USABLE_FLAGS | DB_INTERNAL_FLAGS) & \
|
||||
(ENV_USABLE_FLAGS | ENV_INTERNAL_FLAGS))
|
||||
#error "Oops, some flags overlapped or wrong"
|
||||
#endif
|
||||
|
||||
/* Merge flags and avoid false MDBX_UTTERLY_NOSYNC */
|
||||
static uint32_t merge_flags(const uint32_t a, const uint32_t b) {
|
||||
uint32_t r = a | b;
|
||||
|
@@ -195,10 +195,6 @@ extern LIBMDBX_API const char *const mdbx_sourcery_anchor;
|
||||
#define MAIN_DBI 1
|
||||
/* Number of DBs in metapage (free and main) - also hardcoded elsewhere */
|
||||
#define CORE_DBS 2
|
||||
#define MAX_DBI (INT16_MAX - CORE_DBS)
|
||||
#if MAX_DBI != MDBX_MAX_DBI
|
||||
#error "Oops, MAX_DBI != MDBX_MAX_DBI"
|
||||
#endif
|
||||
|
||||
/* Number of meta pages - also hardcoded elsewhere */
|
||||
#define NUM_METAS 3
|
||||
@@ -1379,3 +1375,25 @@ static __pure_function __always_inline __maybe_unused size_t
|
||||
ceil_powerof2(size_t value, size_t granularity) {
|
||||
return floor_powerof2(value + granularity - 1, granularity);
|
||||
}
|
||||
|
||||
/* 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. */
|
||||
#define ENV_CHANGEABLE_FLAGS \
|
||||
(MDBX_SAFE_NOSYNC | MDBX_NOMETASYNC | MDBX_MAPASYNC | MDBX_NOMEMINIT | \
|
||||
MDBX_COALESCE | MDBX_PAGEPERTURB | MDBX_ACCEDE)
|
||||
#define ENV_CHANGELESS_FLAGS \
|
||||
(MDBX_NOSUBDIR | MDBX_RDONLY | MDBX_WRITEMAP | MDBX_NOTLS | MDBX_NORDAHEAD | \
|
||||
MDBX_LIFORECLAIM | MDBX_EXCLUSIVE)
|
||||
#define ENV_USABLE_FLAGS (ENV_CHANGEABLE_FLAGS | ENV_CHANGELESS_FLAGS)
|
||||
|
||||
static __maybe_unused void static_checks(void) {
|
||||
STATIC_ASSERT_MSG(INT16_MAX - CORE_DBS == MDBX_MAX_DBI,
|
||||
"Oops, MDBX_MAX_DBI or CORE_DBS?");
|
||||
STATIC_ASSERT_MSG((MDBX_ACCEDE | MDBX_CREATE) ==
|
||||
((DB_USABLE_FLAGS | DB_INTERNAL_FLAGS) &
|
||||
(ENV_USABLE_FLAGS | ENV_INTERNAL_FLAGS)),
|
||||
"Oops, some flags overlapped or wrong");
|
||||
STATIC_ASSERT_MSG((ENV_INTERNAL_FLAGS & ENV_USABLE_FLAGS) == 0,
|
||||
"Oops, some flags overlapped or wrong");
|
||||
}
|
||||
|
@@ -77,7 +77,8 @@ struct {
|
||||
short *pagemap;
|
||||
uint64_t total_payload_bytes;
|
||||
uint64_t pgcount;
|
||||
walk_dbi_t dbi[MAX_DBI + CORE_DBS + /* account pseudo-entry for meta */ 1];
|
||||
walk_dbi_t
|
||||
dbi[MDBX_MAX_DBI + CORE_DBS + /* account pseudo-entry for meta */ 1];
|
||||
} walk;
|
||||
|
||||
#define dbi_free walk.dbi[FREE_DBI]
|
||||
@@ -1032,7 +1033,7 @@ int main(int argc, char *argv[]) {
|
||||
return rc < 0 ? EXIT_FAILURE_MDB : EXIT_FAILURE_SYS;
|
||||
}
|
||||
|
||||
rc = mdbx_env_set_maxdbs(env, MAX_DBI);
|
||||
rc = mdbx_env_set_maxdbs(env, MDBX_MAX_DBI);
|
||||
if (rc) {
|
||||
error("mdbx_env_set_maxdbs failed, error %d %s\n", rc, mdbx_strerror(rc));
|
||||
goto bailout;
|
||||
|
Reference in New Issue
Block a user