mirror of
https://github.com/isar/libmdbx.git
synced 2025-10-19 10:18:56 +08:00
mdbx: extract internal osal_yield()
(backport).
This commit is contained in:
@@ -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) || \
|
#elif defined(__mips) || defined(__mips__) || defined(__mips64) || defined(__mips64__) || defined(_M_MRX000) || \
|
||||||
defined(_MIPS_) || defined(__MWERKS__) || defined(__sgi)
|
defined(_MIPS_) || defined(__MWERKS__) || defined(__sgi)
|
||||||
__asm__ __volatile__(".word 0x00000140");
|
__asm__ __volatile__(".word 0x00000140");
|
||||||
#elif defined(__linux__) || defined(__gnu_linux__) || defined(_UNIX03_SOURCE)
|
#else
|
||||||
sched_yield();
|
osal_yield();
|
||||||
#elif (defined(_GNU_SOURCE) && __GLIBC_PREREQ(2, 1)) || defined(_OPEN_THREADS)
|
|
||||||
pthread_yield();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -103,15 +103,7 @@ __cold int coherency_timeout(uint64_t *timestamp, intptr_t pgno, const MDBX_env
|
|||||||
}
|
}
|
||||||
|
|
||||||
osal_memory_fence(mo_AcquireRelease, true);
|
osal_memory_fence(mo_AcquireRelease, true);
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
osal_yield();
|
||||||
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
|
|
||||||
return MDBX_RESULT_TRUE;
|
return MDBX_RESULT_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -172,13 +172,8 @@ int dbi_defer_release(MDBX_env *const env, defer_free_item_t *const chain) {
|
|||||||
#endif /* MDBX_ENABLE_DBI_LOCKFREE */
|
#endif /* MDBX_ENABLE_DBI_LOCKFREE */
|
||||||
|
|
||||||
ENSURE(env, osal_fastmutex_release(&env->dbi_lock) == MDBX_SUCCESS);
|
ENSURE(env, osal_fastmutex_release(&env->dbi_lock) == MDBX_SUCCESS);
|
||||||
if (length > 42) {
|
if (length > 42)
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
osal_yield();
|
||||||
SwitchToThread();
|
|
||||||
#else
|
|
||||||
sched_yield();
|
|
||||||
#endif /* Windows */
|
|
||||||
}
|
|
||||||
while (obsolete_chain) {
|
while (obsolete_chain) {
|
||||||
defer_free_item_t *item = obsolete_chain;
|
defer_free_item_t *item = obsolete_chain;
|
||||||
obsolete_chain = obsolete_chain->next;
|
obsolete_chain = obsolete_chain->next;
|
||||||
|
@@ -2638,7 +2638,7 @@ __cold void osal_jitter(bool tiny) {
|
|||||||
break;
|
break;
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
if (coin < 43 * 2 / 3)
|
if (coin < 43 * 2 / 3)
|
||||||
SwitchToThread();
|
osal_yield();
|
||||||
else {
|
else {
|
||||||
static HANDLE timer;
|
static HANDLE timer;
|
||||||
if (!timer)
|
if (!timer)
|
||||||
@@ -2653,7 +2653,7 @@ __cold void osal_jitter(bool tiny) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
sched_yield();
|
osal_yield();
|
||||||
if (coin > 43 * 2 / 3)
|
if (coin > 43 * 2 / 3)
|
||||||
usleep(coin);
|
usleep(coin);
|
||||||
#endif
|
#endif
|
||||||
|
@@ -171,6 +171,14 @@ typedef char pathchar_t;
|
|||||||
#define MDBX_PRIsPATH "s"
|
#define MDBX_PRIsPATH "s"
|
||||||
#endif
|
#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 {
|
typedef struct osal_mmap {
|
||||||
union {
|
union {
|
||||||
void *base;
|
void *base;
|
||||||
|
@@ -572,11 +572,6 @@ int osal_actor_poll(mdbx_pid_t &pid, unsigned timeout) {
|
|||||||
return sigbreak ? EINTR : 0 /* timeout */;
|
return sigbreak ? EINTR : 0 /* timeout */;
|
||||||
}
|
}
|
||||||
|
|
||||||
void osal_yield(void) {
|
|
||||||
if (sched_yield())
|
|
||||||
failure_perror("sched_yield()", errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
void osal_udelay(size_t us) {
|
void osal_udelay(size_t us) {
|
||||||
chrono::time until, now = chrono::now_monotonic();
|
chrono::time until, now = chrono::now_monotonic();
|
||||||
until.fixedpoint = now.fixedpoint + chrono::from_us(us).fixedpoint;
|
until.fixedpoint = now.fixedpoint + chrono::from_us(us).fixedpoint;
|
||||||
|
@@ -401,8 +401,6 @@ int osal_actor_poll(mdbx_pid_t &pid, unsigned timeout) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void osal_yield(void) { SwitchToThread(); }
|
|
||||||
|
|
||||||
void osal_udelay(size_t us) {
|
void osal_udelay(size_t us) {
|
||||||
chrono::time until, now = chrono::now_monotonic();
|
chrono::time until, now = chrono::now_monotonic();
|
||||||
until.fixedpoint = now.fixedpoint + chrono::from_us(us).fixedpoint;
|
until.fixedpoint = now.fixedpoint + chrono::from_us(us).fixedpoint;
|
||||||
|
@@ -20,7 +20,6 @@ bool osal_multiactor_mode(void);
|
|||||||
|
|
||||||
int osal_delay(unsigned seconds);
|
int osal_delay(unsigned seconds);
|
||||||
void osal_udelay(size_t us);
|
void osal_udelay(size_t us);
|
||||||
void osal_yield(void);
|
|
||||||
bool osal_istty(int fd);
|
bool osal_istty(int fd);
|
||||||
std::string osal_tempdir(void);
|
std::string osal_tempdir(void);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user