mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 17:34:14 +08:00
mdbx: add mdbx_osal_jitter() and mdbx_jitter4testing().
This commit is contained in:
parent
40dee6f05f
commit
7204c46421
@ -799,6 +799,14 @@ void mdbx_panic(const char *fmt, ...)
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
static __inline void mdbx_jitter4testing(bool tiny) {
|
||||
#ifndef NDEBUG
|
||||
mdbx_osal_jitter(tiny);
|
||||
#else
|
||||
(void)tiny;
|
||||
#endif
|
||||
}
|
||||
|
||||
int mdbx_reader_check0(MDB_env *env, int rlocked, int *dead);
|
||||
|
||||
#define METAPAGE_1(env) (&((MDB_metabuf *)(env)->me_map)->mb_metabuf.mm_meta)
|
||||
|
@ -24,19 +24,6 @@
|
||||
* LY
|
||||
*/
|
||||
|
||||
static __inline void jitter4testing(void) {
|
||||
#ifndef NDEBUG
|
||||
for (;;) {
|
||||
unsigned coin = ((unsigned)__rdtsc() * 277u) % 43u;
|
||||
if (coin < 43 / 3)
|
||||
break;
|
||||
SwitchToThread();
|
||||
if (coin > 43 * 2 / 3)
|
||||
Sleep(1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* rthc */
|
||||
|
||||
|
26
src/osal.c
26
src/osal.c
@ -626,3 +626,29 @@ int mdbx_mlock(const void *address, size_t length) {
|
||||
return (mlock(address, length) == 0) ? MDB_SUCCESS : errno;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
__cold void mdbx_osal_jitter(bool tiny) {
|
||||
for (;;) {
|
||||
#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || \
|
||||
defined(__x86_64__)
|
||||
const unsigned salt = 277u * (unsigned)__rdtsc();
|
||||
#else
|
||||
const unsigned salt = rand();
|
||||
#endif
|
||||
|
||||
const unsigned coin = salt % (tiny ? 29u : 43u);
|
||||
if (coin < 43 / 3)
|
||||
break;
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
SwitchToThread();
|
||||
if (coin > 43 * 2 / 3)
|
||||
Sleep(1);
|
||||
#else
|
||||
sched_yield();
|
||||
if (coin > 43 * 2 / 3)
|
||||
usleep(coin);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -383,6 +383,8 @@ static __inline mdbx_pid_t mdbx_getpid(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void mdbx_osal_jitter(bool tiny);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef mdbx_assert_fail
|
||||
|
Loading…
x
Reference in New Issue
Block a user