mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-29 08:28:21 +08:00
mdbx: вынесение статических переменных в структуру mdbx_static
.
This commit is contained in:
parent
f548f00d8e
commit
af060b4960
31
src/core.c
31
src/core.c
@ -3233,9 +3233,8 @@ static __always_inline int __must_check_result dpl_append(MDBX_txn *txn,
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
uint8_t runtime_flags = MDBX_RUNTIME_FLAGS_INIT;
|
||||
uint8_t loglevel = MDBX_LOG_FATAL;
|
||||
MDBX_debug_func *debug_logger;
|
||||
MDBX_INTERNAL_VAR_INSTA struct mdbx_static mdbx_static = {
|
||||
MDBX_RUNTIME_FLAGS_INIT, MDBX_LOG_FATAL, nullptr, 0, nullptr};
|
||||
|
||||
static __must_check_result __inline int page_retire(MDBX_cursor *mc,
|
||||
MDBX_page *mp);
|
||||
@ -3588,8 +3587,8 @@ const char *mdbx_strerror_ANSI2OEM(int errnum) {
|
||||
|
||||
__cold void debug_log_va(int level, const char *function, int line,
|
||||
const char *fmt, va_list args) {
|
||||
if (debug_logger)
|
||||
debug_logger(level, function, line, fmt, args);
|
||||
if (mdbx_static.logger)
|
||||
mdbx_static.logger(level, function, line, fmt, args);
|
||||
else {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
if (IsDebuggerPresent()) {
|
||||
@ -9243,7 +9242,7 @@ static int txn_renew(MDBX_txn *txn, const unsigned flags) {
|
||||
r = thread_rthc_get(env->me_txkey);
|
||||
if (likely(r)) {
|
||||
if (unlikely(!r->mr_pid.weak) &&
|
||||
(runtime_flags & MDBX_DBG_LEGACY_MULTIOPEN)) {
|
||||
(mdbx_static.flags & MDBX_DBG_LEGACY_MULTIOPEN)) {
|
||||
thread_rthc_set(env->me_txkey, nullptr);
|
||||
r = nullptr;
|
||||
} else {
|
||||
@ -9367,7 +9366,7 @@ static int txn_renew(MDBX_txn *txn, const unsigned flags) {
|
||||
return MDBX_BUSY;
|
||||
MDBX_lockinfo *const lck = env->me_lck_mmap.lck;
|
||||
if (lck && (env->me_flags & MDBX_NOTLS) == 0 &&
|
||||
(runtime_flags & MDBX_DBG_LEGACY_OVERLAP) == 0) {
|
||||
(mdbx_static.flags & MDBX_DBG_LEGACY_OVERLAP) == 0) {
|
||||
const size_t snap_nreaders =
|
||||
atomic_load32(&lck->mti_numreaders, mo_AcquireRelease);
|
||||
for (size_t i = 0; i < snap_nreaders; ++i) {
|
||||
@ -9772,7 +9771,7 @@ int mdbx_txn_begin_ex(MDBX_env *env, MDBX_txn *parent, MDBX_txn_flags_t flags,
|
||||
} else if (flags & MDBX_TXN_RDONLY) {
|
||||
if (env->me_txn0 &&
|
||||
unlikely(env->me_txn0->mt_owner == osal_thread_self()) && env->me_txn &&
|
||||
(runtime_flags & MDBX_DBG_LEGACY_OVERLAP) == 0)
|
||||
(mdbx_static.flags & MDBX_DBG_LEGACY_OVERLAP) == 0)
|
||||
return MDBX_TXN_OVERLAPPING;
|
||||
} else {
|
||||
/* Reuse preallocated write txn. However, do not touch it until
|
||||
@ -14339,7 +14338,7 @@ __cold static int setup_dxb(MDBX_env *env, const int lck_rc,
|
||||
return err;
|
||||
#endif /* MADV_DONTDUMP */
|
||||
#if defined(MADV_DODUMP)
|
||||
if (runtime_flags & MDBX_DBG_DUMP) {
|
||||
if (mdbx_static.flags & MDBX_DBG_DUMP) {
|
||||
const size_t meta_length_aligned2os = pgno_align2os_bytes(env, NUM_METAS);
|
||||
err = madvise(env->me_map, meta_length_aligned2os, MADV_DODUMP)
|
||||
? ignore_enosys(errno)
|
||||
@ -14589,7 +14588,7 @@ __cold static int setup_dxb(MDBX_env *env, const int lck_rc,
|
||||
bytes2pgno(env, used_aligned2os_bytes), mo_Relaxed);
|
||||
|
||||
if ((env->me_flags & MDBX_RDONLY) == 0 && env->me_stuck_meta < 0 &&
|
||||
(runtime_flags & MDBX_DBG_DONT_UPGRADE) == 0) {
|
||||
(mdbx_static.flags & MDBX_DBG_DONT_UPGRADE) == 0) {
|
||||
for (int n = 0; n < NUM_METAS; ++n) {
|
||||
MDBX_meta *const meta = METAPAGE(env, n);
|
||||
if (unlikely(unaligned_peek_u64(4, &meta->mm_magic_and_version) !=
|
||||
@ -14697,7 +14696,7 @@ __cold static int setup_lck_locked(MDBX_env *env) {
|
||||
if (unlikely(MDBX_IS_ERROR(err)))
|
||||
return err;
|
||||
if (inprocess_neighbor) {
|
||||
if ((runtime_flags & MDBX_DBG_LEGACY_MULTIOPEN) == 0 ||
|
||||
if ((mdbx_static.flags & MDBX_DBG_LEGACY_MULTIOPEN) == 0 ||
|
||||
(inprocess_neighbor->me_flags & MDBX_EXCLUSIVE) != 0)
|
||||
return MDBX_BUSY;
|
||||
if (lck_seize_rc == MDBX_RESULT_TRUE) {
|
||||
@ -14929,7 +14928,7 @@ __cold static int __must_check_result override_meta(MDBX_env *env,
|
||||
target, "pre", constmeta_txnid(shape));
|
||||
return MDBX_PROBLEM;
|
||||
}
|
||||
if (runtime_flags & MDBX_DBG_DONT_UPGRADE)
|
||||
if (mdbx_static.flags & MDBX_DBG_DONT_UPGRADE)
|
||||
memcpy(&model->mm_magic_and_version, &shape->mm_magic_and_version,
|
||||
sizeof(model->mm_magic_and_version));
|
||||
model->mm_extra_flags = shape->mm_extra_flags;
|
||||
@ -24624,10 +24623,10 @@ __cold MDBX_INTERNAL_FUNC int cleanup_dead_readers(MDBX_env *env,
|
||||
|
||||
__cold int mdbx_setup_debug(MDBX_log_level_t level, MDBX_debug_flags_t flags,
|
||||
MDBX_debug_func *logger) {
|
||||
const int rc = runtime_flags | (loglevel << 16);
|
||||
const int rc = mdbx_static.flags | (mdbx_static.loglevel << 16);
|
||||
|
||||
if (level != MDBX_LOG_DONTCHANGE)
|
||||
loglevel = (uint8_t)level;
|
||||
mdbx_static.loglevel = (uint8_t)level;
|
||||
|
||||
if (flags != MDBX_DBG_DONTCHANGE) {
|
||||
flags &=
|
||||
@ -24636,11 +24635,11 @@ __cold int mdbx_setup_debug(MDBX_log_level_t level, MDBX_debug_flags_t flags,
|
||||
#endif
|
||||
MDBX_DBG_DUMP | MDBX_DBG_LEGACY_MULTIOPEN | MDBX_DBG_LEGACY_OVERLAP |
|
||||
MDBX_DBG_DONT_UPGRADE;
|
||||
runtime_flags = (uint8_t)flags;
|
||||
mdbx_static.flags = (uint8_t)flags;
|
||||
}
|
||||
|
||||
if (logger != MDBX_LOGGER_DONTCHANGE)
|
||||
debug_logger = logger;
|
||||
mdbx_static.logger = logger;
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -24,11 +24,13 @@
|
||||
#ifdef xMDBX_ALLOY
|
||||
/* Amalgamated build */
|
||||
#define MDBX_INTERNAL_FUNC static
|
||||
#define MDBX_INTERNAL_VAR static
|
||||
#define MDBX_INTERNAL_VAR_PROTO static
|
||||
#define MDBX_INTERNAL_VAR_INSTA static
|
||||
#else
|
||||
/* Non-amalgamated build */
|
||||
#define MDBX_INTERNAL_FUNC
|
||||
#define MDBX_INTERNAL_VAR extern
|
||||
#define MDBX_INTERNAL_VAR_PROTO extern
|
||||
#define MDBX_INTERNAL_VAR_INSTA
|
||||
#endif /* xMDBX_ALLOY */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@ -242,13 +244,17 @@ extern LIBMDBX_API const char *const mdbx_sourcery_anchor;
|
||||
#define MDBX_RUNTIME_FLAGS_INIT \
|
||||
((MDBX_DEBUG) > 0) * MDBX_DBG_ASSERT + ((MDBX_DEBUG) > 1) * MDBX_DBG_AUDIT
|
||||
|
||||
extern uint8_t runtime_flags;
|
||||
extern uint8_t loglevel;
|
||||
extern MDBX_debug_func *debug_logger;
|
||||
MDBX_INTERNAL_VAR_PROTO struct mdbx_static {
|
||||
uint8_t flags;
|
||||
uint8_t loglevel;
|
||||
MDBX_debug_func *logger;
|
||||
size_t logger_buffer_size;
|
||||
char *logger_buffer;
|
||||
} mdbx_static;
|
||||
|
||||
MDBX_MAYBE_UNUSED static __inline void jitter4testing(bool tiny) {
|
||||
#if MDBX_DEBUG
|
||||
if (MDBX_DBG_JITTER & runtime_flags)
|
||||
if (MDBX_DBG_JITTER & mdbx_static.flags)
|
||||
osal_jitter(tiny);
|
||||
#else
|
||||
(void)tiny;
|
||||
@ -262,17 +268,17 @@ MDBX_INTERNAL_FUNC void debug_log_va(int level, const char *function, int line,
|
||||
const char *fmt, va_list args);
|
||||
|
||||
#if MDBX_DEBUG
|
||||
#define LOG_ENABLED(msg) unlikely(msg <= loglevel)
|
||||
#define AUDIT_ENABLED() unlikely((runtime_flags & MDBX_DBG_AUDIT))
|
||||
#define LOG_ENABLED(msg) unlikely(msg <= mdbx_static.loglevel)
|
||||
#define AUDIT_ENABLED() unlikely((mdbx_static.flags & MDBX_DBG_AUDIT))
|
||||
#else /* MDBX_DEBUG */
|
||||
#define LOG_ENABLED(msg) (msg < MDBX_LOG_VERBOSE && msg <= loglevel)
|
||||
#define LOG_ENABLED(msg) (msg < MDBX_LOG_VERBOSE && msg <= mdbx_static.loglevel)
|
||||
#define AUDIT_ENABLED() (0)
|
||||
#endif /* MDBX_DEBUG */
|
||||
|
||||
#if MDBX_FORCE_ASSERTIONS
|
||||
#define ASSERT_ENABLED() (1)
|
||||
#elif MDBX_DEBUG
|
||||
#define ASSERT_ENABLED() likely((runtime_flags & MDBX_DBG_ASSERT))
|
||||
#define ASSERT_ENABLED() likely((mdbx_static.flags & MDBX_DBG_ASSERT))
|
||||
#else
|
||||
#define ASSERT_ENABLED() (0)
|
||||
#endif /* assertions */
|
||||
|
@ -27,10 +27,9 @@
|
||||
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#ifndef xMDBX_ALLOY
|
||||
uint32_t linux_kernel_version;
|
||||
bool mdbx_RunningOnWSL1;
|
||||
#endif /* xMDBX_ALLOY */
|
||||
MDBX_INTERNAL_VAR_INSTA uint32_t linux_kernel_version;
|
||||
MDBX_INTERNAL_VAR_INSTA bool
|
||||
mdbx_RunningOnWSL1 /* Windows Subsystem 1 for Linux */;
|
||||
|
||||
MDBX_EXCLUDE_FOR_GPROF
|
||||
__cold static uint8_t probe_for_WSL(const char *tag) {
|
||||
@ -170,7 +169,7 @@ mdbx_global_destructor(void) {
|
||||
static int op_setlk, op_setlkw, op_getlk;
|
||||
__cold static void choice_fcntl(void) {
|
||||
assert(!op_setlk && !op_setlkw && !op_getlk);
|
||||
if ((runtime_flags & MDBX_DBG_LEGACY_MULTIOPEN) == 0
|
||||
if ((mdbx_static.flags & MDBX_DBG_LEGACY_MULTIOPEN) == 0
|
||||
#if defined(__linux__) || defined(__gnu_linux__)
|
||||
&& linux_kernel_version >
|
||||
0x030f0000 /* OFD locks are available since 3.15, but engages here
|
||||
|
10
src/osal.c
10
src/osal.c
@ -244,7 +244,7 @@ MDBX_NORETURN __cold void assert_fail(const char *msg, const char *func,
|
||||
unsigned line) {
|
||||
#endif /* MDBX_DEBUG */
|
||||
|
||||
if (debug_logger)
|
||||
if (mdbx_static.logger)
|
||||
debug_log(MDBX_LOG_FATAL, func, line, "assert: %s\n", msg);
|
||||
else {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
@ -287,7 +287,7 @@ __cold void mdbx_panic(const char *fmt, ...) {
|
||||
? "<troubles with panic-message preparation>"
|
||||
: message;
|
||||
|
||||
if (debug_logger)
|
||||
if (mdbx_static.logger)
|
||||
debug_log(MDBX_LOG_FATAL, "panic", 0, "%s", const_message);
|
||||
|
||||
while (1) {
|
||||
@ -3488,10 +3488,8 @@ __cold int mdbx_get_sysraminfo(intptr_t *page_size, intptr_t *total_pages,
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
#ifndef xMDBX_ALLOY
|
||||
unsigned sys_pagesize;
|
||||
MDBX_MAYBE_UNUSED unsigned sys_pagesize_ln2, sys_allocation_granularity;
|
||||
#endif /* xMDBX_ALLOY */
|
||||
MDBX_INTERNAL_VAR_INSTA unsigned sys_pagesize, sys_pagesize_ln2,
|
||||
sys_allocation_granularity;
|
||||
|
||||
void osal_ctor(void) {
|
||||
#if MDBX_HAVE_PWRITEV && defined(_SC_IOV_MAX)
|
||||
|
33
src/osal.h
33
src/osal.h
@ -210,8 +210,8 @@ typedef pthread_mutex_t osal_fastmutex_t;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* OS abstraction layer stuff */
|
||||
|
||||
MDBX_INTERNAL_VAR unsigned sys_pagesize;
|
||||
MDBX_MAYBE_UNUSED MDBX_INTERNAL_VAR unsigned sys_pagesize_ln2,
|
||||
MDBX_INTERNAL_VAR_PROTO unsigned sys_pagesize;
|
||||
MDBX_MAYBE_UNUSED MDBX_INTERNAL_VAR_PROTO unsigned sys_pagesize_ln2,
|
||||
sys_allocation_granularity;
|
||||
|
||||
/* Get the size of a memory page for the system.
|
||||
@ -475,8 +475,9 @@ MDBX_MAYBE_UNUSED static __inline void jitter4testing(bool tiny);
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) || defined(__gnu_linux__)
|
||||
MDBX_INTERNAL_VAR uint32_t linux_kernel_version;
|
||||
MDBX_INTERNAL_VAR bool mdbx_RunningOnWSL1 /* Windows Subsystem 1 for Linux */;
|
||||
MDBX_INTERNAL_VAR_PROTO uint32_t linux_kernel_version;
|
||||
MDBX_INTERNAL_VAR_PROTO bool
|
||||
mdbx_RunningOnWSL1 /* Windows Subsystem 1 for Linux */;
|
||||
#endif /* Linux */
|
||||
|
||||
#ifndef osal_strdup
|
||||
@ -763,7 +764,7 @@ MDBX_INTERNAL_FUNC int osal_rpid_check(MDBX_env *env, uint32_t pid);
|
||||
MDBX_INTERNAL_FUNC int osal_mb2w(const char *const src, wchar_t **const pdst);
|
||||
|
||||
typedef void(WINAPI *osal_srwlock_t_function)(osal_srwlock_t *);
|
||||
MDBX_INTERNAL_VAR osal_srwlock_t_function osal_srwlock_Init,
|
||||
MDBX_INTERNAL_VAR_PROTO osal_srwlock_t_function osal_srwlock_Init,
|
||||
osal_srwlock_AcquireShared, osal_srwlock_ReleaseShared,
|
||||
osal_srwlock_AcquireExclusive, osal_srwlock_ReleaseExclusive;
|
||||
|
||||
@ -816,7 +817,7 @@ typedef struct _FILE_REMOTE_PROTOCOL_INFO {
|
||||
typedef BOOL(WINAPI *MDBX_GetFileInformationByHandleEx)(
|
||||
_In_ HANDLE hFile, _In_ FILE_INFO_BY_HANDLE_CLASS FileInformationClass,
|
||||
_Out_ LPVOID lpFileInformation, _In_ DWORD dwBufferSize);
|
||||
MDBX_INTERNAL_VAR MDBX_GetFileInformationByHandleEx
|
||||
MDBX_INTERNAL_VAR_PROTO MDBX_GetFileInformationByHandleEx
|
||||
mdbx_GetFileInformationByHandleEx;
|
||||
|
||||
typedef BOOL(WINAPI *MDBX_GetVolumeInformationByHandleW)(
|
||||
@ -825,19 +826,20 @@ typedef BOOL(WINAPI *MDBX_GetVolumeInformationByHandleW)(
|
||||
_Out_opt_ LPDWORD lpMaximumComponentLength,
|
||||
_Out_opt_ LPDWORD lpFileSystemFlags,
|
||||
_Out_opt_ LPWSTR lpFileSystemNameBuffer, _In_ DWORD nFileSystemNameSize);
|
||||
MDBX_INTERNAL_VAR MDBX_GetVolumeInformationByHandleW
|
||||
MDBX_INTERNAL_VAR_PROTO MDBX_GetVolumeInformationByHandleW
|
||||
mdbx_GetVolumeInformationByHandleW;
|
||||
|
||||
typedef DWORD(WINAPI *MDBX_GetFinalPathNameByHandleW)(_In_ HANDLE hFile,
|
||||
_Out_ LPWSTR lpszFilePath,
|
||||
_In_ DWORD cchFilePath,
|
||||
_In_ DWORD dwFlags);
|
||||
MDBX_INTERNAL_VAR MDBX_GetFinalPathNameByHandleW mdbx_GetFinalPathNameByHandleW;
|
||||
MDBX_INTERNAL_VAR_PROTO MDBX_GetFinalPathNameByHandleW
|
||||
mdbx_GetFinalPathNameByHandleW;
|
||||
|
||||
typedef BOOL(WINAPI *MDBX_SetFileInformationByHandle)(
|
||||
_In_ HANDLE hFile, _In_ FILE_INFO_BY_HANDLE_CLASS FileInformationClass,
|
||||
_Out_ LPVOID lpFileInformation, _In_ DWORD dwBufferSize);
|
||||
MDBX_INTERNAL_VAR MDBX_SetFileInformationByHandle
|
||||
MDBX_INTERNAL_VAR_PROTO MDBX_SetFileInformationByHandle
|
||||
mdbx_SetFileInformationByHandle;
|
||||
|
||||
typedef NTSTATUS(NTAPI *MDBX_NtFsControlFile)(
|
||||
@ -846,10 +848,10 @@ typedef NTSTATUS(NTAPI *MDBX_NtFsControlFile)(
|
||||
OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG FsControlCode,
|
||||
IN OUT PVOID InputBuffer, IN ULONG InputBufferLength,
|
||||
OUT OPTIONAL PVOID OutputBuffer, IN ULONG OutputBufferLength);
|
||||
MDBX_INTERNAL_VAR MDBX_NtFsControlFile mdbx_NtFsControlFile;
|
||||
MDBX_INTERNAL_VAR_PROTO MDBX_NtFsControlFile mdbx_NtFsControlFile;
|
||||
|
||||
typedef uint64_t(WINAPI *MDBX_GetTickCount64)(void);
|
||||
MDBX_INTERNAL_VAR MDBX_GetTickCount64 mdbx_GetTickCount64;
|
||||
MDBX_INTERNAL_VAR_PROTO MDBX_GetTickCount64 mdbx_GetTickCount64;
|
||||
|
||||
#if !defined(_WIN32_WINNT_WIN8) || _WIN32_WINNT < _WIN32_WINNT_WIN8
|
||||
typedef struct _WIN32_MEMORY_RANGE_ENTRY {
|
||||
@ -861,13 +863,13 @@ typedef struct _WIN32_MEMORY_RANGE_ENTRY {
|
||||
typedef BOOL(WINAPI *MDBX_PrefetchVirtualMemory)(
|
||||
HANDLE hProcess, ULONG_PTR NumberOfEntries,
|
||||
PWIN32_MEMORY_RANGE_ENTRY VirtualAddresses, ULONG Flags);
|
||||
MDBX_INTERNAL_VAR MDBX_PrefetchVirtualMemory mdbx_PrefetchVirtualMemory;
|
||||
MDBX_INTERNAL_VAR_PROTO MDBX_PrefetchVirtualMemory mdbx_PrefetchVirtualMemory;
|
||||
|
||||
typedef enum _SECTION_INHERIT { ViewShare = 1, ViewUnmap = 2 } SECTION_INHERIT;
|
||||
|
||||
typedef NTSTATUS(NTAPI *MDBX_NtExtendSection)(IN HANDLE SectionHandle,
|
||||
IN PLARGE_INTEGER NewSectionSize);
|
||||
MDBX_INTERNAL_VAR MDBX_NtExtendSection mdbx_NtExtendSection;
|
||||
MDBX_INTERNAL_VAR_PROTO MDBX_NtExtendSection mdbx_NtExtendSection;
|
||||
|
||||
static __inline bool mdbx_RunningUnderWine(void) {
|
||||
return !mdbx_NtExtendSection;
|
||||
@ -877,14 +879,15 @@ typedef LSTATUS(WINAPI *MDBX_RegGetValueA)(HKEY hkey, LPCSTR lpSubKey,
|
||||
LPCSTR lpValue, DWORD dwFlags,
|
||||
LPDWORD pdwType, PVOID pvData,
|
||||
LPDWORD pcbData);
|
||||
MDBX_INTERNAL_VAR MDBX_RegGetValueA mdbx_RegGetValueA;
|
||||
MDBX_INTERNAL_VAR_PROTO MDBX_RegGetValueA mdbx_RegGetValueA;
|
||||
|
||||
NTSYSAPI ULONG RtlRandomEx(PULONG Seed);
|
||||
|
||||
typedef BOOL(WINAPI *MDBX_SetFileIoOverlappedRange)(HANDLE FileHandle,
|
||||
PUCHAR OverlappedRangeStart,
|
||||
ULONG Length);
|
||||
MDBX_INTERNAL_VAR MDBX_SetFileIoOverlappedRange mdbx_SetFileIoOverlappedRange;
|
||||
MDBX_INTERNAL_VAR_PROTO MDBX_SetFileIoOverlappedRange
|
||||
mdbx_SetFileIoOverlappedRange;
|
||||
|
||||
#endif /* Windows */
|
||||
|
||||
|
@ -97,7 +97,8 @@
|
||||
#include <vector>
|
||||
|
||||
#define MDBX_INTERNAL_FUNC
|
||||
#define MDBX_INTERNAL_VAR extern
|
||||
#define MDBX_INTERNAL_VAR_PROTO extern
|
||||
#define MDBX_INTERNAL_VAR_INSTA
|
||||
#define xMDBX_TOOLS /* Avoid using internal eASSERT() */
|
||||
#include "../mdbx.h++"
|
||||
#include "../src/base.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user