mdbx: extract internal osal_yield().

This commit is contained in:
Леонид Юрьев (Leonid Yuriev)
2025-09-07 13:16:22 +03:00
parent 74ef6502e3
commit 815d483803
8 changed files with 15 additions and 30 deletions

View File

@@ -171,10 +171,8 @@ MDBX_MAYBE_UNUSED static __always_inline void atomic_yield(void) {
#elif defined(__mips) || defined(__mips__) || defined(__mips64) || defined(__mips64__) || defined(_M_MRX000) || \
defined(_MIPS_) || defined(__MWERKS__) || defined(__sgi)
__asm__ __volatile__(".word 0x00000140");
#elif defined(__linux__) || defined(__gnu_linux__) || defined(_UNIX03_SOURCE)
sched_yield();
#elif (defined(_GNU_SOURCE) && __GLIBC_PREREQ(2, 1)) || defined(_OPEN_THREADS)
pthread_yield();
#else
osal_yield();
#endif
}

View File

@@ -103,15 +103,7 @@ __cold int coherency_timeout(uint64_t *timestamp, intptr_t pgno, const MDBX_env
}
osal_memory_fence(mo_AcquireRelease, true);
#if defined(_WIN32) || defined(_WIN64)
SwitchToThread();
#elif defined(__linux__) || defined(__gnu_linux__) || defined(_UNIX03_SOURCE)
sched_yield();
#elif (defined(_GNU_SOURCE) && __GLIBC_PREREQ(2, 1)) || defined(_OPEN_THREADS)
pthread_yield();
#else
usleep(42);
#endif
osal_yield();
return MDBX_RESULT_TRUE;
}

View File

@@ -166,13 +166,8 @@ int dbi_defer_release(MDBX_env *const env, defer_free_item_t *const chain) {
#endif /* MDBX_ENABLE_DBI_LOCKFREE */
ENSURE(env, osal_fastmutex_release(&env->dbi_lock) == MDBX_SUCCESS);
if (length > 42) {
#if defined(_WIN32) || defined(_WIN64)
SwitchToThread();
#else
sched_yield();
#endif /* Windows */
}
if (length > 42)
osal_yield();
while (obsolete_chain) {
defer_free_item_t *item = obsolete_chain;
obsolete_chain = obsolete_chain->next;

View File

@@ -2624,7 +2624,7 @@ __cold void osal_jitter(bool tiny) {
break;
#if defined(_WIN32) || defined(_WIN64)
if (coin < 43 * 2 / 3)
SwitchToThread();
osal_yield();
else {
static HANDLE timer;
if (!timer)
@@ -2639,7 +2639,7 @@ __cold void osal_jitter(bool tiny) {
break;
}
#else
sched_yield();
osal_yield();
if (coin > 43 * 2 / 3)
usleep(coin);
#endif

View File

@@ -171,6 +171,14 @@ typedef char pathchar_t;
#define MDBX_PRIsPATH "s"
#endif
static inline bool osal_yield(void) {
#if defined(_WIN32) || defined(_WIN64)
return SleepEx(0, true) == WAIT_IO_COMPLETION;
#else
return sched_yield() != 0;
#endif
}
typedef struct osal_mmap {
union {
void *base;