mdbx: cleanup redundant MDBX_INTERNAL (backport).

This commit is contained in:
Леонид Юрьев (Leonid Yuriev)
2025-08-23 11:24:19 +03:00
parent f4dafd62d1
commit 339be13778
5 changed files with 87 additions and 88 deletions

View File

@@ -155,7 +155,7 @@ static int lck_op(const mdbx_filehandle_t fd, int cmd, const int lck, const off_
} }
} }
MDBX_INTERNAL int osal_lockfile(mdbx_filehandle_t fd, bool wait) { int osal_lockfile(mdbx_filehandle_t fd, bool wait) {
#if MDBX_USE_OFDLOCKS #if MDBX_USE_OFDLOCKS
if (unlikely(op_setlk == 0)) if (unlikely(op_setlk == 0))
choice_fcntl(); choice_fcntl();
@@ -163,7 +163,7 @@ MDBX_INTERNAL int osal_lockfile(mdbx_filehandle_t fd, bool wait) {
return lck_op(fd, wait ? op_setlkw : op_setlk, F_WRLCK, 0, OFF_T_MAX); return lck_op(fd, wait ? op_setlkw : op_setlk, F_WRLCK, 0, OFF_T_MAX);
} }
MDBX_INTERNAL int lck_rpid_set(MDBX_env *env) { int lck_rpid_set(MDBX_env *env) {
assert(env->lck_mmap.fd != INVALID_HANDLE_VALUE); assert(env->lck_mmap.fd != INVALID_HANDLE_VALUE);
assert(env->pid > 0); assert(env->pid > 0);
if (unlikely(osal_getpid() != env->pid)) if (unlikely(osal_getpid() != env->pid))
@@ -171,13 +171,13 @@ MDBX_INTERNAL int lck_rpid_set(MDBX_env *env) {
return lck_op(env->lck_mmap.fd, op_setlk, F_WRLCK, env->pid, 1); return lck_op(env->lck_mmap.fd, op_setlk, F_WRLCK, env->pid, 1);
} }
MDBX_INTERNAL int lck_rpid_clear(MDBX_env *env) { int lck_rpid_clear(MDBX_env *env) {
assert(env->lck_mmap.fd != INVALID_HANDLE_VALUE); assert(env->lck_mmap.fd != INVALID_HANDLE_VALUE);
assert(env->pid > 0); assert(env->pid > 0);
return lck_op(env->lck_mmap.fd, op_setlk, F_UNLCK, env->pid, 1); return lck_op(env->lck_mmap.fd, op_setlk, F_UNLCK, env->pid, 1);
} }
MDBX_INTERNAL int lck_rpid_check(MDBX_env *env, uint32_t pid) { int lck_rpid_check(MDBX_env *env, uint32_t pid) {
assert(env->lck_mmap.fd != INVALID_HANDLE_VALUE); assert(env->lck_mmap.fd != INVALID_HANDLE_VALUE);
assert(pid > 0); assert(pid > 0);
return lck_op(env->lck_mmap.fd, op_getlk, F_WRLCK, pid, 1); return lck_op(env->lck_mmap.fd, op_getlk, F_WRLCK, pid, 1);
@@ -186,7 +186,7 @@ MDBX_INTERNAL int lck_rpid_check(MDBX_env *env, uint32_t pid) {
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#if MDBX_LOCKING > MDBX_LOCKING_SYSV #if MDBX_LOCKING > MDBX_LOCKING_SYSV
MDBX_INTERNAL int lck_ipclock_stubinit(osal_ipclock_t *ipc) { int lck_ipclock_stubinit(osal_ipclock_t *ipc) {
#if MDBX_LOCKING == MDBX_LOCKING_POSIX1988 #if MDBX_LOCKING == MDBX_LOCKING_POSIX1988
return sem_init(ipc, false, 1) ? errno : 0; return sem_init(ipc, false, 1) ? errno : 0;
#elif MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || MDBX_LOCKING == MDBX_LOCKING_POSIX2008 #elif MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || MDBX_LOCKING == MDBX_LOCKING_POSIX2008
@@ -196,7 +196,7 @@ MDBX_INTERNAL int lck_ipclock_stubinit(osal_ipclock_t *ipc) {
#endif #endif
} }
MDBX_INTERNAL int lck_ipclock_destroy(osal_ipclock_t *ipc) { int lck_ipclock_destroy(osal_ipclock_t *ipc) {
#if MDBX_LOCKING == MDBX_LOCKING_POSIX1988 #if MDBX_LOCKING == MDBX_LOCKING_POSIX1988
return sem_destroy(ipc) ? errno : 0; return sem_destroy(ipc) ? errno : 0;
#elif MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || MDBX_LOCKING == MDBX_LOCKING_POSIX2008 #elif MDBX_LOCKING == MDBX_LOCKING_POSIX2001 || MDBX_LOCKING == MDBX_LOCKING_POSIX2008
@@ -260,7 +260,7 @@ static int check_fstat(MDBX_env *env) {
return rc; return rc;
} }
__cold MDBX_INTERNAL int lck_seize(MDBX_env *env) { __cold int lck_seize(MDBX_env *env) {
assert(env->lazy_fd != INVALID_HANDLE_VALUE); assert(env->lazy_fd != INVALID_HANDLE_VALUE);
if (unlikely(osal_getpid() != env->pid)) if (unlikely(osal_getpid() != env->pid))
return MDBX_PANIC; return MDBX_PANIC;
@@ -384,7 +384,7 @@ retry:
return MDBX_RESULT_FALSE; return MDBX_RESULT_FALSE;
} }
MDBX_INTERNAL int lck_downgrade(MDBX_env *env) { int lck_downgrade(MDBX_env *env) {
assert(env->lck_mmap.fd != INVALID_HANDLE_VALUE); assert(env->lck_mmap.fd != INVALID_HANDLE_VALUE);
if (unlikely(osal_getpid() != env->pid)) if (unlikely(osal_getpid() != env->pid))
return MDBX_PANIC; return MDBX_PANIC;
@@ -404,7 +404,7 @@ MDBX_INTERNAL int lck_downgrade(MDBX_env *env) {
return rc; return rc;
} }
MDBX_INTERNAL int lck_upgrade(MDBX_env *env, bool dont_wait) { int lck_upgrade(MDBX_env *env, bool dont_wait) {
assert(env->lck_mmap.fd != INVALID_HANDLE_VALUE); assert(env->lck_mmap.fd != INVALID_HANDLE_VALUE);
if (unlikely(osal_getpid() != env->pid)) if (unlikely(osal_getpid() != env->pid))
return MDBX_PANIC; return MDBX_PANIC;
@@ -428,7 +428,7 @@ MDBX_INTERNAL int lck_upgrade(MDBX_env *env, bool dont_wait) {
return rc; return rc;
} }
__cold MDBX_INTERNAL int lck_destroy(MDBX_env *env, MDBX_env *inprocess_neighbor, const uint32_t current_pid) { __cold int lck_destroy(MDBX_env *env, MDBX_env *inprocess_neighbor, const uint32_t current_pid) {
eASSERT(env, osal_getpid() == current_pid); eASSERT(env, osal_getpid() == current_pid);
int rc = MDBX_SUCCESS; int rc = MDBX_SUCCESS;
struct stat lck_info; struct stat lck_info;
@@ -517,7 +517,7 @@ __cold MDBX_INTERNAL int lck_destroy(MDBX_env *env, MDBX_env *inprocess_neighbor
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
__cold MDBX_INTERNAL int lck_init(MDBX_env *env, MDBX_env *inprocess_neighbor, int global_uniqueness_flag) { __cold int lck_init(MDBX_env *env, MDBX_env *inprocess_neighbor, int global_uniqueness_flag) {
#if MDBX_LOCKING == MDBX_LOCKING_SYSV #if MDBX_LOCKING == MDBX_LOCKING_SYSV
int semid = -1; int semid = -1;
/* don't initialize semaphores twice */ /* don't initialize semaphores twice */
@@ -727,7 +727,7 @@ __cold static int osal_ipclock_failed(MDBX_env *env, osal_ipclock_t *ipc, const
} }
#if defined(__ANDROID_API__) || defined(ANDROID) || defined(BIONIC) #if defined(__ANDROID_API__) || defined(ANDROID) || defined(BIONIC)
MDBX_INTERNAL int osal_check_tid4bionic(void) { int osal_check_tid4bionic(void) {
/* avoid 32-bit Bionic bug/hang with 32-pit TID */ /* avoid 32-bit Bionic bug/hang with 32-pit TID */
if (sizeof(pthread_mutex_t) < sizeof(pid_t) + sizeof(unsigned)) { if (sizeof(pthread_mutex_t) < sizeof(pid_t) + sizeof(unsigned)) {
pid_t tid = gettid(); pid_t tid = gettid();
@@ -810,7 +810,7 @@ static int osal_ipclock_unlock(MDBX_env *env, osal_ipclock_t *ipc) {
return rc; return rc;
} }
MDBX_INTERNAL int lck_rdt_lock(MDBX_env *env) { int lck_rdt_lock(MDBX_env *env) {
TRACE("%s", ">>"); TRACE("%s", ">>");
jitter4testing(true); jitter4testing(true);
int rc = osal_ipclock_lock(env, &env->lck->rdt_lock, false); int rc = osal_ipclock_lock(env, &env->lck->rdt_lock, false);
@@ -818,7 +818,7 @@ MDBX_INTERNAL int lck_rdt_lock(MDBX_env *env) {
return rc; return rc;
} }
MDBX_INTERNAL void lck_rdt_unlock(MDBX_env *env) { void lck_rdt_unlock(MDBX_env *env) {
TRACE("%s", ">>"); TRACE("%s", ">>");
int err = osal_ipclock_unlock(env, &env->lck->rdt_lock); int err = osal_ipclock_unlock(env, &env->lck->rdt_lock);
TRACE("<< err %d", err); TRACE("<< err %d", err);

View File

@@ -140,7 +140,7 @@ void lck_txn_unlock(MDBX_env *env) {
#define LCK_LOWER LCK_LO_OFFSET, LCK_LO_LEN #define LCK_LOWER LCK_LO_OFFSET, LCK_LO_LEN
#define LCK_UPPER LCK_UP_OFFSET, LCK_UP_LEN #define LCK_UPPER LCK_UP_OFFSET, LCK_UP_LEN
MDBX_INTERNAL int lck_rdt_lock(MDBX_env *env) { int lck_rdt_lock(MDBX_env *env) {
imports.srwl_AcquireShared(&env->remap_guard); imports.srwl_AcquireShared(&env->remap_guard);
if (env->lck_mmap.fd == INVALID_HANDLE_VALUE) if (env->lck_mmap.fd == INVALID_HANDLE_VALUE)
return MDBX_SUCCESS; /* readonly database in readonly filesystem */ return MDBX_SUCCESS; /* readonly database in readonly filesystem */
@@ -158,7 +158,7 @@ MDBX_INTERNAL int lck_rdt_lock(MDBX_env *env) {
return rc; return rc;
} }
MDBX_INTERNAL void lck_rdt_unlock(MDBX_env *env) { void lck_rdt_unlock(MDBX_env *env) {
if (env->lck_mmap.fd != INVALID_HANDLE_VALUE && (env->flags & MDBX_EXCLUSIVE) == 0) { if (env->lck_mmap.fd != INVALID_HANDLE_VALUE && (env->flags & MDBX_EXCLUSIVE) == 0) {
/* transition from S-E (locked) to S-? (used), e.g. unlock upper-part */ /* transition from S-E (locked) to S-? (used), e.g. unlock upper-part */
int err = funlock(env->lck_mmap.fd, LCK_UPPER); int err = funlock(env->lck_mmap.fd, LCK_UPPER);
@@ -168,7 +168,7 @@ MDBX_INTERNAL void lck_rdt_unlock(MDBX_env *env) {
imports.srwl_ReleaseShared(&env->remap_guard); imports.srwl_ReleaseShared(&env->remap_guard);
} }
MDBX_INTERNAL int osal_lockfile(mdbx_filehandle_t fd, bool wait) { int osal_lockfile(mdbx_filehandle_t fd, bool wait) {
return flock(fd, wait ? LCK_EXCLUSIVE | LCK_WAITFOR : LCK_EXCLUSIVE | LCK_DONTWAIT, 0, DXB_MAXLEN); return flock(fd, wait ? LCK_EXCLUSIVE | LCK_WAITFOR : LCK_EXCLUSIVE | LCK_DONTWAIT, 0, DXB_MAXLEN);
} }
@@ -204,7 +204,7 @@ static int suspend_and_append(mdbx_handle_array_t **array, const DWORD ThreadId)
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL int osal_suspend_threads_before_remap(MDBX_env *env, mdbx_handle_array_t **array) { int osal_suspend_threads_before_remap(MDBX_env *env, mdbx_handle_array_t **array) {
eASSERT(env, (env->flags & MDBX_NOSTICKYTHREADS) == 0); eASSERT(env, (env->flags & MDBX_NOSTICKYTHREADS) == 0);
const uintptr_t CurrentTid = GetCurrentThreadId(); const uintptr_t CurrentTid = GetCurrentThreadId();
int rc; int rc;
@@ -271,7 +271,7 @@ MDBX_INTERNAL int osal_suspend_threads_before_remap(MDBX_env *env, mdbx_handle_a
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL int osal_resume_threads_after_remap(mdbx_handle_array_t *array) { int osal_resume_threads_after_remap(mdbx_handle_array_t *array) {
int rc = MDBX_SUCCESS; int rc = MDBX_SUCCESS;
for (unsigned i = 0; i < array->count; ++i) { for (unsigned i = 0; i < array->count; ++i) {
const HANDLE hThread = array->handles[i]; const HANDLE hThread = array->handles[i];
@@ -407,7 +407,7 @@ static int internal_seize_lck(HANDLE lfd) {
return rc; return rc;
} }
MDBX_INTERNAL int lck_seize(MDBX_env *env) { int lck_seize(MDBX_env *env) {
const HANDLE fd4data = env->ioring.overlapped_fd ? env->ioring.overlapped_fd : env->lazy_fd; const HANDLE fd4data = env->ioring.overlapped_fd ? env->ioring.overlapped_fd : env->lazy_fd;
assert(fd4data != INVALID_HANDLE_VALUE); assert(fd4data != INVALID_HANDLE_VALUE);
if (env->flags & MDBX_EXCLUSIVE) if (env->flags & MDBX_EXCLUSIVE)
@@ -449,7 +449,7 @@ MDBX_INTERNAL int lck_seize(MDBX_env *env) {
return rc; return rc;
} }
MDBX_INTERNAL int lck_downgrade(MDBX_env *env) { int lck_downgrade(MDBX_env *env) {
const HANDLE fd4data = env->ioring.overlapped_fd ? env->ioring.overlapped_fd : env->lazy_fd; const HANDLE fd4data = env->ioring.overlapped_fd ? env->ioring.overlapped_fd : env->lazy_fd;
/* Transite from exclusive-write state (E-E) to used (S-?) */ /* Transite from exclusive-write state (E-E) to used (S-?) */
assert(fd4data != INVALID_HANDLE_VALUE); assert(fd4data != INVALID_HANDLE_VALUE);
@@ -479,7 +479,7 @@ MDBX_INTERNAL int lck_downgrade(MDBX_env *env) {
return MDBX_SUCCESS /* 5) now at S-? (used), done */; return MDBX_SUCCESS /* 5) now at S-? (used), done */;
} }
MDBX_INTERNAL int lck_upgrade(MDBX_env *env, bool dont_wait) { int lck_upgrade(MDBX_env *env, bool dont_wait) {
/* Transite from used state (S-?) to exclusive-write (E-E) */ /* Transite from used state (S-?) to exclusive-write (E-E) */
assert(env->lck_mmap.fd != INVALID_HANDLE_VALUE); assert(env->lck_mmap.fd != INVALID_HANDLE_VALUE);
@@ -513,7 +513,7 @@ MDBX_INTERNAL int lck_upgrade(MDBX_env *env, bool dont_wait) {
return MDBX_SUCCESS /* 6) now at E-E (exclusive-write), done */; return MDBX_SUCCESS /* 6) now at E-E (exclusive-write), done */;
} }
MDBX_INTERNAL int lck_init(MDBX_env *env, MDBX_env *inprocess_neighbor, int global_uniqueness_flag) { int lck_init(MDBX_env *env, MDBX_env *inprocess_neighbor, int global_uniqueness_flag) {
(void)env; (void)env;
(void)inprocess_neighbor; (void)inprocess_neighbor;
(void)global_uniqueness_flag; (void)global_uniqueness_flag;
@@ -534,7 +534,7 @@ MDBX_INTERNAL int lck_init(MDBX_env *env, MDBX_env *inprocess_neighbor, int glob
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL int lck_destroy(MDBX_env *env, MDBX_env *inprocess_neighbor, const uint32_t current_pid) { int lck_destroy(MDBX_env *env, MDBX_env *inprocess_neighbor, const uint32_t current_pid) {
(void)current_pid; (void)current_pid;
/* LY: should unmap before releasing the locks to avoid race condition and /* LY: should unmap before releasing the locks to avoid race condition and
* STATUS_USER_MAPPED_FILE/ERROR_USER_MAPPED_FILE */ * STATUS_USER_MAPPED_FILE/ERROR_USER_MAPPED_FILE */
@@ -555,12 +555,12 @@ MDBX_INTERNAL int lck_destroy(MDBX_env *env, MDBX_env *inprocess_neighbor, const
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
/* reader checking (by pid) */ /* reader checking (by pid) */
MDBX_INTERNAL int lck_rpid_set(MDBX_env *env) { int lck_rpid_set(MDBX_env *env) {
(void)env; (void)env;
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL int lck_rpid_clear(MDBX_env *env) { int lck_rpid_clear(MDBX_env *env) {
(void)env; (void)env;
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
@@ -571,7 +571,7 @@ MDBX_INTERNAL int lck_rpid_clear(MDBX_env *env) {
* MDBX_RESULT_TRUE, if pid is live (unable to acquire lock) * MDBX_RESULT_TRUE, if pid is live (unable to acquire lock)
* MDBX_RESULT_FALSE, if pid is dead (lock acquired) * MDBX_RESULT_FALSE, if pid is dead (lock acquired)
* or otherwise the errcode. */ * or otherwise the errcode. */
MDBX_INTERNAL int lck_rpid_check(MDBX_env *env, uint32_t pid) { int lck_rpid_check(MDBX_env *env, uint32_t pid) {
(void)env; (void)env;
HANDLE hProcess = OpenProcess(SYNCHRONIZE, FALSE, pid); HANDLE hProcess = OpenProcess(SYNCHRONIZE, FALSE, pid);
int rc; int rc;

View File

@@ -204,7 +204,7 @@ static bool pid_insert(uint32_t *list, uint32_t pid) {
return true; return true;
} }
__cold MDBX_INTERNAL int mvcc_cleanup_dead(MDBX_env *env, int rdt_locked, int *dead) { __cold int mvcc_cleanup_dead(MDBX_env *env, int rdt_locked, int *dead) {
int rc = check_env(env, true); int rc = check_env(env, true);
if (unlikely(rc != MDBX_SUCCESS)) if (unlikely(rc != MDBX_SUCCESS))
return rc; return rc;

View File

@@ -271,7 +271,7 @@ __cold void mdbx_panic(const char *fmt, ...) {
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
#ifndef osal_vasprintf #ifndef osal_vasprintf
MDBX_INTERNAL int osal_vasprintf(char **strp, const char *fmt, va_list ap) { int osal_vasprintf(char **strp, const char *fmt, va_list ap) {
va_list ones; va_list ones;
va_copy(ones, ap); va_copy(ones, ap);
const int needed = vsnprintf(nullptr, 0, fmt, ones); const int needed = vsnprintf(nullptr, 0, fmt, ones);
@@ -303,7 +303,7 @@ MDBX_INTERNAL int osal_vasprintf(char **strp, const char *fmt, va_list ap) {
#endif /* osal_vasprintf */ #endif /* osal_vasprintf */
#ifndef osal_asprintf #ifndef osal_asprintf
MDBX_INTERNAL int osal_asprintf(char **strp, const char *fmt, ...) { int osal_asprintf(char **strp, const char *fmt, ...) {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
const int rc = osal_vasprintf(strp, fmt, ap); const int rc = osal_vasprintf(strp, fmt, ap);
@@ -313,7 +313,7 @@ MDBX_INTERNAL int osal_asprintf(char **strp, const char *fmt, ...) {
#endif /* osal_asprintf */ #endif /* osal_asprintf */
#ifndef osal_memalign_alloc #ifndef osal_memalign_alloc
MDBX_INTERNAL int osal_memalign_alloc(size_t alignment, size_t bytes, void **result) { int osal_memalign_alloc(size_t alignment, size_t bytes, void **result) {
assert(is_powerof2(alignment) && alignment >= sizeof(void *)); assert(is_powerof2(alignment) && alignment >= sizeof(void *));
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
(void)alignment; (void)alignment;
@@ -335,7 +335,7 @@ MDBX_INTERNAL int osal_memalign_alloc(size_t alignment, size_t bytes, void **res
#endif /* osal_memalign_alloc */ #endif /* osal_memalign_alloc */
#ifndef osal_memalign_free #ifndef osal_memalign_free
MDBX_INTERNAL void osal_memalign_free(void *ptr) { void osal_memalign_free(void *ptr) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
VirtualFree(ptr, 0, MEM_RELEASE); VirtualFree(ptr, 0, MEM_RELEASE);
#else #else
@@ -358,7 +358,7 @@ char *osal_strdup(const char *str) {
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
MDBX_INTERNAL int osal_condpair_init(osal_condpair_t *condpair) { int osal_condpair_init(osal_condpair_t *condpair) {
int rc; int rc;
memset(condpair, 0, sizeof(osal_condpair_t)); memset(condpair, 0, sizeof(osal_condpair_t));
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@@ -397,7 +397,7 @@ bailout_mutex:
return rc; return rc;
} }
MDBX_INTERNAL int osal_condpair_destroy(osal_condpair_t *condpair) { int osal_condpair_destroy(osal_condpair_t *condpair) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
int rc = CloseHandle(condpair->mutex) ? MDBX_SUCCESS : (int)GetLastError(); int rc = CloseHandle(condpair->mutex) ? MDBX_SUCCESS : (int)GetLastError();
rc = CloseHandle(condpair->event[0]) ? rc : (int)GetLastError(); rc = CloseHandle(condpair->event[0]) ? rc : (int)GetLastError();
@@ -411,7 +411,7 @@ MDBX_INTERNAL int osal_condpair_destroy(osal_condpair_t *condpair) {
return rc; return rc;
} }
MDBX_INTERNAL int osal_condpair_lock(osal_condpair_t *condpair) { int osal_condpair_lock(osal_condpair_t *condpair) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
DWORD code = WaitForSingleObject(condpair->mutex, INFINITE); DWORD code = WaitForSingleObject(condpair->mutex, INFINITE);
return waitstatus2errcode(code); return waitstatus2errcode(code);
@@ -420,7 +420,7 @@ MDBX_INTERNAL int osal_condpair_lock(osal_condpair_t *condpair) {
#endif #endif
} }
MDBX_INTERNAL int osal_condpair_unlock(osal_condpair_t *condpair) { int osal_condpair_unlock(osal_condpair_t *condpair) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
return ReleaseMutex(condpair->mutex) ? MDBX_SUCCESS : (int)GetLastError(); return ReleaseMutex(condpair->mutex) ? MDBX_SUCCESS : (int)GetLastError();
#else #else
@@ -428,7 +428,7 @@ MDBX_INTERNAL int osal_condpair_unlock(osal_condpair_t *condpair) {
#endif #endif
} }
MDBX_INTERNAL int osal_condpair_signal(osal_condpair_t *condpair, bool part) { int osal_condpair_signal(osal_condpair_t *condpair, bool part) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
return SetEvent(condpair->event[part]) ? MDBX_SUCCESS : (int)GetLastError(); return SetEvent(condpair->event[part]) ? MDBX_SUCCESS : (int)GetLastError();
#else #else
@@ -436,7 +436,7 @@ MDBX_INTERNAL int osal_condpair_signal(osal_condpair_t *condpair, bool part) {
#endif #endif
} }
MDBX_INTERNAL int osal_condpair_wait(osal_condpair_t *condpair, bool part) { int osal_condpair_wait(osal_condpair_t *condpair, bool part) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
DWORD code = SignalObjectAndWait(condpair->mutex, condpair->event[part], INFINITE, FALSE); DWORD code = SignalObjectAndWait(condpair->mutex, condpair->event[part], INFINITE, FALSE);
if (code == WAIT_OBJECT_0) { if (code == WAIT_OBJECT_0) {
@@ -452,7 +452,7 @@ MDBX_INTERNAL int osal_condpair_wait(osal_condpair_t *condpair, bool part) {
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
MDBX_INTERNAL int osal_fastmutex_init(osal_fastmutex_t *fastmutex) { int osal_fastmutex_init(osal_fastmutex_t *fastmutex) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
InitializeCriticalSection(fastmutex); InitializeCriticalSection(fastmutex);
return MDBX_SUCCESS; return MDBX_SUCCESS;
@@ -471,7 +471,7 @@ MDBX_INTERNAL int osal_fastmutex_init(osal_fastmutex_t *fastmutex) {
#endif #endif
} }
MDBX_INTERNAL int osal_fastmutex_destroy(osal_fastmutex_t *fastmutex) { int osal_fastmutex_destroy(osal_fastmutex_t *fastmutex) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
DeleteCriticalSection(fastmutex); DeleteCriticalSection(fastmutex);
return MDBX_SUCCESS; return MDBX_SUCCESS;
@@ -480,7 +480,7 @@ MDBX_INTERNAL int osal_fastmutex_destroy(osal_fastmutex_t *fastmutex) {
#endif #endif
} }
MDBX_INTERNAL int osal_fastmutex_acquire(osal_fastmutex_t *fastmutex) { int osal_fastmutex_acquire(osal_fastmutex_t *fastmutex) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
__try { __try {
EnterCriticalSection(fastmutex); EnterCriticalSection(fastmutex);
@@ -495,7 +495,7 @@ MDBX_INTERNAL int osal_fastmutex_acquire(osal_fastmutex_t *fastmutex) {
#endif #endif
} }
MDBX_INTERNAL int osal_fastmutex_release(osal_fastmutex_t *fastmutex) { int osal_fastmutex_release(osal_fastmutex_t *fastmutex) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
LeaveCriticalSection(fastmutex); LeaveCriticalSection(fastmutex);
return MDBX_SUCCESS; return MDBX_SUCCESS;
@@ -508,7 +508,7 @@ MDBX_INTERNAL int osal_fastmutex_release(osal_fastmutex_t *fastmutex) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
MDBX_INTERNAL int osal_mb2w(const char *const src, wchar_t **const pdst) { int osal_mb2w(const char *const src, wchar_t **const pdst) {
const size_t dst_wlen = MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, src, -1, nullptr, 0); const size_t dst_wlen = MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, src, -1, nullptr, 0);
wchar_t *dst = *pdst; wchar_t *dst = *pdst;
int rc = ERROR_INVALID_NAME; int rc = ERROR_INVALID_NAME;
@@ -578,10 +578,10 @@ static size_t osal_iov_max;
#undef OSAL_IOV_MAX #undef OSAL_IOV_MAX
#endif /* OSAL_IOV_MAX */ #endif /* OSAL_IOV_MAX */
MDBX_INTERNAL int osal_ioring_create(osal_ioring_t *ior int osal_ioring_create(osal_ioring_t *ior
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
, ,
bool enable_direct, mdbx_filehandle_t overlapped_fd bool enable_direct, mdbx_filehandle_t overlapped_fd
#endif /* Windows */ #endif /* Windows */
) { ) {
memset(ior, 0, sizeof(osal_ioring_t)); memset(ior, 0, sizeof(osal_ioring_t));
@@ -624,7 +624,7 @@ static inline ior_item_t *ior_next(ior_item_t *item, size_t sgvcnt) {
#endif #endif
} }
MDBX_INTERNAL int osal_ioring_add(osal_ioring_t *ior, const size_t offset, void *data, const size_t bytes) { int osal_ioring_add(osal_ioring_t *ior, const size_t offset, void *data, const size_t bytes) {
assert(bytes && data); assert(bytes && data);
assert(bytes % MDBX_MIN_PAGESIZE == 0 && bytes <= MAX_WRITE); assert(bytes % MDBX_MIN_PAGESIZE == 0 && bytes <= MAX_WRITE);
assert(offset % MDBX_MIN_PAGESIZE == 0 && offset + (uint64_t)bytes <= MAX_MAPSIZE); assert(offset % MDBX_MIN_PAGESIZE == 0 && offset + (uint64_t)bytes <= MAX_MAPSIZE);
@@ -736,8 +736,8 @@ MDBX_INTERNAL int osal_ioring_add(osal_ioring_t *ior, const size_t offset, void
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL void osal_ioring_walk(osal_ioring_t *ior, iov_ctx_t *ctx, void osal_ioring_walk(osal_ioring_t *ior, iov_ctx_t *ctx,
void (*callback)(iov_ctx_t *ctx, size_t offset, void *data, size_t bytes)) { void (*callback)(iov_ctx_t *ctx, size_t offset, void *data, size_t bytes)) {
for (ior_item_t *item = ior->pool; item <= ior->last;) { for (ior_item_t *item = ior->pool; item <= ior->last;) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
size_t offset = ior_offset(item); size_t offset = ior_offset(item);
@@ -778,7 +778,7 @@ MDBX_INTERNAL void osal_ioring_walk(osal_ioring_t *ior, iov_ctx_t *ctx,
} }
} }
MDBX_INTERNAL osal_ioring_write_result_t osal_ioring_write(osal_ioring_t *ior, mdbx_filehandle_t fd) { osal_ioring_write_result_t osal_ioring_write(osal_ioring_t *ior, mdbx_filehandle_t fd) {
osal_ioring_write_result_t r = {MDBX_SUCCESS, 0}; osal_ioring_write_result_t r = {MDBX_SUCCESS, 0};
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@@ -999,7 +999,7 @@ MDBX_INTERNAL osal_ioring_write_result_t osal_ioring_write(osal_ioring_t *ior, m
return r; return r;
} }
MDBX_INTERNAL void osal_ioring_reset(osal_ioring_t *ior) { void osal_ioring_reset(osal_ioring_t *ior) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
if (ior->last) { if (ior->last) {
for (ior_item_t *item = ior->pool; item <= ior->last;) { for (ior_item_t *item = ior->pool; item <= ior->last;) {
@@ -1041,7 +1041,7 @@ static void ior_cleanup(osal_ioring_t *ior, const size_t since) {
#endif /* Windows */ #endif /* Windows */
} }
MDBX_INTERNAL int osal_ioring_resize(osal_ioring_t *ior, size_t items) { int osal_ioring_resize(osal_ioring_t *ior, size_t items) {
assert(items > 0 && items < INT_MAX / sizeof(ior_item_t)); assert(items > 0 && items < INT_MAX / sizeof(ior_item_t));
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
if (ior->state & IOR_STATE_LOCKED) if (ior->state & IOR_STATE_LOCKED)
@@ -1093,7 +1093,7 @@ MDBX_INTERNAL int osal_ioring_resize(osal_ioring_t *ior, size_t items) {
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL void osal_ioring_destroy(osal_ioring_t *ior) { void osal_ioring_destroy(osal_ioring_t *ior) {
if (ior->allocated) if (ior->allocated)
ior_cleanup(ior, 0); ior_cleanup(ior, 0);
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@@ -1110,7 +1110,7 @@ MDBX_INTERNAL void osal_ioring_destroy(osal_ioring_t *ior) {
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
MDBX_INTERNAL int osal_removefile(const pathchar_t *pathname) { int osal_removefile(const pathchar_t *pathname) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
return DeleteFileW(pathname) ? MDBX_SUCCESS : (int)GetLastError(); return DeleteFileW(pathname) ? MDBX_SUCCESS : (int)GetLastError();
#else #else
@@ -1122,7 +1122,7 @@ MDBX_INTERNAL int osal_removefile(const pathchar_t *pathname) {
static bool is_valid_fd(int fd) { return !(isatty(fd) < 0 && errno == EBADF); } static bool is_valid_fd(int fd) { return !(isatty(fd) < 0 && errno == EBADF); }
#endif /*! Windows */ #endif /*! Windows */
MDBX_INTERNAL int osal_removedirectory(const pathchar_t *pathname) { int osal_removedirectory(const pathchar_t *pathname) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
return RemoveDirectoryW(pathname) ? MDBX_SUCCESS : (int)GetLastError(); return RemoveDirectoryW(pathname) ? MDBX_SUCCESS : (int)GetLastError();
#else #else
@@ -1130,7 +1130,7 @@ MDBX_INTERNAL int osal_removedirectory(const pathchar_t *pathname) {
#endif #endif
} }
MDBX_INTERNAL int osal_fileexists(const pathchar_t *pathname) { int osal_fileexists(const pathchar_t *pathname) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
if (GetFileAttributesW(pathname) != INVALID_FILE_ATTRIBUTES) if (GetFileAttributesW(pathname) != INVALID_FILE_ATTRIBUTES)
return MDBX_RESULT_TRUE; return MDBX_RESULT_TRUE;
@@ -1144,7 +1144,7 @@ MDBX_INTERNAL int osal_fileexists(const pathchar_t *pathname) {
#endif #endif
} }
MDBX_INTERNAL pathchar_t *osal_fileext(const pathchar_t *pathname, size_t len) { pathchar_t *osal_fileext(const pathchar_t *pathname, size_t len) {
const pathchar_t *ext = nullptr; const pathchar_t *ext = nullptr;
for (size_t i = 0; i < len && pathname[i]; i++) for (size_t i = 0; i < len && pathname[i]; i++)
if (pathname[i] == '.') if (pathname[i] == '.')
@@ -1154,7 +1154,7 @@ MDBX_INTERNAL pathchar_t *osal_fileext(const pathchar_t *pathname, size_t len) {
return (pathchar_t *)ext; return (pathchar_t *)ext;
} }
MDBX_INTERNAL bool osal_pathequal(const pathchar_t *l, const pathchar_t *r, size_t len) { bool osal_pathequal(const pathchar_t *l, const pathchar_t *r, size_t len) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
for (size_t i = 0; i < len; ++i) { for (size_t i = 0; i < len; ++i) {
pathchar_t a = l[i]; pathchar_t a = l[i];
@@ -1170,8 +1170,8 @@ MDBX_INTERNAL bool osal_pathequal(const pathchar_t *l, const pathchar_t *r, size
#endif #endif
} }
MDBX_INTERNAL int osal_openfile(const enum osal_openfile_purpose purpose, const MDBX_env *env, int osal_openfile(const enum osal_openfile_purpose purpose, const MDBX_env *env, const pathchar_t *pathname,
const pathchar_t *pathname, mdbx_filehandle_t *fd, mdbx_mode_t unix_mode_bits) { mdbx_filehandle_t *fd, mdbx_mode_t unix_mode_bits) {
*fd = INVALID_HANDLE_VALUE; *fd = INVALID_HANDLE_VALUE;
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@@ -1380,7 +1380,7 @@ MDBX_INTERNAL int osal_openfile(const enum osal_openfile_purpose purpose, const
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL int osal_closefile(mdbx_filehandle_t fd) { int osal_closefile(mdbx_filehandle_t fd) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
return CloseHandle(fd) ? MDBX_SUCCESS : (int)GetLastError(); return CloseHandle(fd) ? MDBX_SUCCESS : (int)GetLastError();
#else #else
@@ -1389,7 +1389,7 @@ MDBX_INTERNAL int osal_closefile(mdbx_filehandle_t fd) {
#endif #endif
} }
MDBX_INTERNAL int osal_pread(mdbx_filehandle_t fd, void *buf, size_t bytes, uint64_t offset) { int osal_pread(mdbx_filehandle_t fd, void *buf, size_t bytes, uint64_t offset) {
if (bytes > MAX_WRITE) if (bytes > MAX_WRITE)
return MDBX_EINVAL; return MDBX_EINVAL;
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@@ -1414,7 +1414,7 @@ MDBX_INTERNAL int osal_pread(mdbx_filehandle_t fd, void *buf, size_t bytes, uint
return (bytes == (size_t)read) ? MDBX_SUCCESS : MDBX_ENODATA; return (bytes == (size_t)read) ? MDBX_SUCCESS : MDBX_ENODATA;
} }
MDBX_INTERNAL int osal_pwrite(mdbx_filehandle_t fd, const void *buf, size_t bytes, uint64_t offset) { int osal_pwrite(mdbx_filehandle_t fd, const void *buf, size_t bytes, uint64_t offset) {
while (true) { while (true) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
OVERLAPPED ov; OVERLAPPED ov;
@@ -1445,7 +1445,7 @@ MDBX_INTERNAL int osal_pwrite(mdbx_filehandle_t fd, const void *buf, size_t byte
} }
} }
MDBX_INTERNAL int osal_write(mdbx_filehandle_t fd, const void *buf, size_t bytes) { int osal_write(mdbx_filehandle_t fd, const void *buf, size_t bytes) {
while (true) { while (true) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
DWORD written; DWORD written;
@@ -1498,7 +1498,7 @@ int osal_pwritev(mdbx_filehandle_t fd, struct iovec *iov, size_t sgvcnt, uint64_
#endif #endif
} }
MDBX_INTERNAL int osal_fsync(mdbx_filehandle_t fd, enum osal_syncmode_bits mode_bits) { int osal_fsync(mdbx_filehandle_t fd, enum osal_syncmode_bits mode_bits) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
if ((mode_bits & (MDBX_SYNC_DATA | MDBX_SYNC_IODQ)) && !FlushFileBuffers(fd)) if ((mode_bits & (MDBX_SYNC_DATA | MDBX_SYNC_IODQ)) && !FlushFileBuffers(fd))
return (int)GetLastError(); return (int)GetLastError();
@@ -1561,7 +1561,7 @@ int osal_filesize(mdbx_filehandle_t fd, uint64_t *length) {
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL int osal_is_pipe(mdbx_filehandle_t fd) { int osal_is_pipe(mdbx_filehandle_t fd) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
switch (GetFileType(fd)) { switch (GetFileType(fd)) {
case FILE_TYPE_DISK: case FILE_TYPE_DISK:
@@ -1593,7 +1593,7 @@ MDBX_INTERNAL int osal_is_pipe(mdbx_filehandle_t fd) {
} }
/* truncate file: just set the length of a file */ /* truncate file: just set the length of a file */
MDBX_INTERNAL int osal_ftruncate(mdbx_filehandle_t fd, uint64_t length) { int osal_ftruncate(mdbx_filehandle_t fd, uint64_t length) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
if (imports.SetFileInformationByHandle) { if (imports.SetFileInformationByHandle) {
FILE_END_OF_FILE_INFO EndOfFileInfo; FILE_END_OF_FILE_INFO EndOfFileInfo;
@@ -1613,7 +1613,7 @@ MDBX_INTERNAL int osal_ftruncate(mdbx_filehandle_t fd, uint64_t length) {
} }
/* extend file: set the length of a file AND ensure the space has been allocated */ /* extend file: set the length of a file AND ensure the space has been allocated */
MDBX_INTERNAL int osal_fallocate(mdbx_filehandle_t fd, uint64_t length) { int osal_fallocate(mdbx_filehandle_t fd, uint64_t length) {
assert(length > 0); assert(length > 0);
int err = MDBX_RESULT_TRUE; int err = MDBX_RESULT_TRUE;
#if (defined(__linux__) || defined(__gnu_linux__)) && \ #if (defined(__linux__) || defined(__gnu_linux__)) && \
@@ -1635,7 +1635,7 @@ MDBX_INTERNAL int osal_fallocate(mdbx_filehandle_t fd, uint64_t length) {
return (err == MDBX_RESULT_TRUE) ? osal_ftruncate(fd, length) : err; return (err == MDBX_RESULT_TRUE) ? osal_ftruncate(fd, length) : err;
} }
MDBX_INTERNAL int osal_fseek(mdbx_filehandle_t fd, uint64_t pos) { int osal_fseek(mdbx_filehandle_t fd, uint64_t pos) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
LARGE_INTEGER li; LARGE_INTEGER li;
li.QuadPart = pos; li.QuadPart = pos;
@@ -1648,8 +1648,7 @@ MDBX_INTERNAL int osal_fseek(mdbx_filehandle_t fd, uint64_t pos) {
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
MDBX_INTERNAL int osal_thread_create(osal_thread_t *thread, THREAD_RESULT(THREAD_CALL *start_routine)(void *), int osal_thread_create(osal_thread_t *thread, THREAD_RESULT(THREAD_CALL *start_routine)(void *), void *arg) {
void *arg) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
*thread = CreateThread(nullptr, 0, start_routine, arg, 0, nullptr); *thread = CreateThread(nullptr, 0, start_routine, arg, 0, nullptr);
return *thread ? MDBX_SUCCESS : (int)GetLastError(); return *thread ? MDBX_SUCCESS : (int)GetLastError();
@@ -1658,7 +1657,7 @@ MDBX_INTERNAL int osal_thread_create(osal_thread_t *thread, THREAD_RESULT(THREAD
#endif #endif
} }
MDBX_INTERNAL int osal_thread_join(osal_thread_t thread) { int osal_thread_join(osal_thread_t thread) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
DWORD code = WaitForSingleObject(thread, INFINITE); DWORD code = WaitForSingleObject(thread, INFINITE);
return waitstatus2errcode(code); return waitstatus2errcode(code);
@@ -1670,7 +1669,7 @@ MDBX_INTERNAL int osal_thread_join(osal_thread_t thread) {
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
MDBX_INTERNAL int osal_msync(const osal_mmap_t *map, size_t offset, size_t length, enum osal_syncmode_bits mode_bits) { int osal_msync(const osal_mmap_t *map, size_t offset, size_t length, enum osal_syncmode_bits mode_bits) {
if (!MDBX_MMAP_NEEDS_JOLT && mode_bits == MDBX_SYNC_NONE) if (!MDBX_MMAP_NEEDS_JOLT && mode_bits == MDBX_SYNC_NONE)
return MDBX_SUCCESS; return MDBX_SUCCESS;
@@ -1701,7 +1700,7 @@ MDBX_INTERNAL int osal_msync(const osal_mmap_t *map, size_t offset, size_t lengt
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL int osal_check_fs_rdonly(mdbx_filehandle_t handle, const pathchar_t *pathname, int err) { int osal_check_fs_rdonly(mdbx_filehandle_t handle, const pathchar_t *pathname, int err) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
(void)pathname; (void)pathname;
(void)err; (void)err;
@@ -1728,7 +1727,7 @@ MDBX_INTERNAL int osal_check_fs_rdonly(mdbx_filehandle_t handle, const pathchar_
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL int osal_check_fs_incore(mdbx_filehandle_t handle) { int osal_check_fs_incore(mdbx_filehandle_t handle) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
(void)handle; (void)handle;
#else #else
@@ -1769,7 +1768,7 @@ MDBX_INTERNAL int osal_check_fs_incore(mdbx_filehandle_t handle) {
return MDBX_RESULT_FALSE; return MDBX_RESULT_FALSE;
} }
MDBX_INTERNAL int osal_check_fs_local(mdbx_filehandle_t handle, int flags) { int osal_check_fs_local(mdbx_filehandle_t handle, int flags) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
if (globals.running_under_Wine && !(flags & MDBX_EXCLUSIVE)) if (globals.running_under_Wine && !(flags & MDBX_EXCLUSIVE))
return ERROR_NOT_CAPABLE /* workaround for Wine */; return ERROR_NOT_CAPABLE /* workaround for Wine */;
@@ -2047,8 +2046,8 @@ static int check_mmap_limit(const size_t limit) {
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL int osal_mmap(const int flags, osal_mmap_t *map, size_t size, const size_t limit, const unsigned options, int osal_mmap(const int flags, osal_mmap_t *map, size_t size, const size_t limit, const unsigned options,
const pathchar_t *pathname4logging) { const pathchar_t *pathname4logging) {
assert(size <= limit); assert(size <= limit);
map->limit = 0; map->limit = 0;
map->current = 0; map->current = 0;
@@ -2200,7 +2199,7 @@ MDBX_INTERNAL int osal_mmap(const int flags, osal_mmap_t *map, size_t size, cons
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL int osal_munmap(osal_mmap_t *map) { int osal_munmap(osal_mmap_t *map) {
VALGRIND_MAKE_MEM_NOACCESS(map->base, map->current); VALGRIND_MAKE_MEM_NOACCESS(map->base, map->current);
/* Unpoisoning is required for ASAN to avoid false-positive diagnostic /* Unpoisoning is required for ASAN to avoid false-positive diagnostic
* when this memory will re-used by malloc or another mmapping. * when this memory will re-used by malloc or another mmapping.
@@ -2226,7 +2225,7 @@ MDBX_INTERNAL int osal_munmap(osal_mmap_t *map) {
return MDBX_SUCCESS; return MDBX_SUCCESS;
} }
MDBX_INTERNAL int osal_mresize(const int flags, osal_mmap_t *map, size_t size, size_t limit) { int osal_mresize(const int flags, osal_mmap_t *map, size_t size, size_t limit) {
int rc = osal_filesize(map->fd, &map->filesize); int rc = osal_filesize(map->fd, &map->filesize);
VERBOSE("flags 0x%x, size %zu, limit %zu, filesize %" PRIu64, flags, size, limit, map->filesize); VERBOSE("flags 0x%x, size %zu, limit %zu, filesize %" PRIu64, flags, size, limit, map->filesize);
assert(size <= limit); assert(size <= limit);
@@ -2605,7 +2604,7 @@ retry_mapview:;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
__cold MDBX_INTERNAL void osal_jitter(bool tiny) { __cold void osal_jitter(bool tiny) {
for (;;) { for (;;) {
#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__x86_64__) #if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__x86_64__)
unsigned salt = 5296013u * (unsigned)__rdtsc(); unsigned salt = 5296013u * (unsigned)__rdtsc();
@@ -2674,7 +2673,7 @@ __cold static clockid_t choice_monoclock(void) {
#define posix_clockid CLOCK_REALTIME #define posix_clockid CLOCK_REALTIME
#endif #endif
MDBX_INTERNAL uint64_t osal_16dot16_to_monotime(uint32_t seconds_16dot16) { uint64_t osal_16dot16_to_monotime(uint32_t seconds_16dot16) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
const uint64_t ratio = performance_frequency.QuadPart; const uint64_t ratio = performance_frequency.QuadPart;
#elif defined(__APPLE__) || defined(__MACH__) #elif defined(__APPLE__) || defined(__MACH__)
@@ -2687,7 +2686,7 @@ MDBX_INTERNAL uint64_t osal_16dot16_to_monotime(uint32_t seconds_16dot16) {
} }
static uint64_t monotime_limit; static uint64_t monotime_limit;
MDBX_INTERNAL uint32_t osal_monotime_to_16dot16(uint64_t monotime) { uint32_t osal_monotime_to_16dot16(uint64_t monotime) {
if (unlikely(monotime > monotime_limit)) if (unlikely(monotime > monotime_limit))
return UINT32_MAX; return UINT32_MAX;
@@ -2702,7 +2701,7 @@ MDBX_INTERNAL uint32_t osal_monotime_to_16dot16(uint64_t monotime) {
return ret; return ret;
} }
MDBX_INTERNAL uint64_t osal_monotime(void) { uint64_t osal_monotime(void) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
LARGE_INTEGER counter; LARGE_INTEGER counter;
if (QueryPerformanceCounter(&counter)) if (QueryPerformanceCounter(&counter))
@@ -2717,7 +2716,7 @@ MDBX_INTERNAL uint64_t osal_monotime(void) {
return 0; return 0;
} }
MDBX_INTERNAL uint64_t osal_cputime(size_t *optional_page_faults) { uint64_t osal_cputime(size_t *optional_page_faults) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
if (optional_page_faults) { if (optional_page_faults) {
PROCESS_MEMORY_COUNTERS pmc; PROCESS_MEMORY_COUNTERS pmc;
@@ -3382,7 +3381,7 @@ __cold int mdbx_get_sysraminfo(intptr_t *page_size, intptr_t *total_pages, intpt
#include <wincrypt.h> #include <wincrypt.h>
#endif /* Windows */ #endif /* Windows */
MDBX_INTERNAL bin128_t osal_guid(const MDBX_env *env) { bin128_t osal_guid(const MDBX_env *env) {
struct { struct {
uint64_t begin, end, cputime; uint64_t begin, end, cputime;
uintptr_t thread, pid; uintptr_t thread, pid;

View File

@@ -3,7 +3,7 @@
#include "internals.h" #include "internals.h"
MDBX_MAYBE_UNUSED MDBX_NOTHROW_CONST_FUNCTION MDBX_INTERNAL unsigned log2n_powerof2(size_t value_uintptr) { MDBX_MAYBE_UNUSED MDBX_NOTHROW_CONST_FUNCTION unsigned log2n_powerof2(size_t value_uintptr) {
assert(value_uintptr > 0 && value_uintptr < INT32_MAX && is_powerof2(value_uintptr)); assert(value_uintptr > 0 && value_uintptr < INT32_MAX && is_powerof2(value_uintptr));
assert((value_uintptr & -(intptr_t)value_uintptr) == value_uintptr); assert((value_uintptr & -(intptr_t)value_uintptr) == value_uintptr);
const uint32_t value_uint32 = (uint32_t)value_uintptr; const uint32_t value_uint32 = (uint32_t)value_uintptr;
@@ -22,7 +22,7 @@ MDBX_MAYBE_UNUSED MDBX_NOTHROW_CONST_FUNCTION MDBX_INTERNAL unsigned log2n_power
#endif #endif
} }
MDBX_NOTHROW_CONST_FUNCTION MDBX_INTERNAL uint64_t rrxmrrxmsx_0(uint64_t v) { MDBX_NOTHROW_CONST_FUNCTION uint64_t rrxmrrxmsx_0(uint64_t v) {
/* Pelle Evensen's mixer, https://bit.ly/2HOfynt */ /* Pelle Evensen's mixer, https://bit.ly/2HOfynt */
v ^= (v << 39 | v >> 25) ^ (v << 14 | v >> 50); v ^= (v << 39 | v >> 25) ^ (v << 14 | v >> 50);
v *= UINT64_C(0xA24BAED4963EE407); v *= UINT64_C(0xA24BAED4963EE407);