2019-11-13 20:14:17 +03:00
|
|
|
/*******************************************************************************
|
|
|
|
*******************************************************************************
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* #### ##### ##### # #### # # ####
|
|
|
|
* # # # # # # # # ## # #
|
|
|
|
* # # # # # # # # # # # ####
|
|
|
|
* # # ##### # # # # # # # #
|
|
|
|
* # # # # # # # # ## # #
|
|
|
|
* #### # # # #### # # ####
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-06-04 20:09:02 +03:00
|
|
|
/* Support for huge write-transactions */
|
|
|
|
#ifndef MDBX_HUGE_TRANSACTIONS
|
|
|
|
#define MDBX_HUGE_TRANSACTIONS 0
|
|
|
|
#endif /* MDBX_HUGE_TRANSACTIONS */
|
|
|
|
|
2019-11-13 20:14:17 +03:00
|
|
|
/* using fcntl(F_FULLFSYNC) with 5-10 times slowdown */
|
|
|
|
#define MDBX_OSX_WANNA_DURABILITY 0
|
|
|
|
/* using fsync() with chance of data lost on power failure */
|
|
|
|
#define MDBX_OSX_WANNA_SPEED 1
|
|
|
|
|
|
|
|
#ifndef MDBX_OSX_SPEED_INSTEADOF_DURABILITY
|
|
|
|
#define MDBX_OSX_SPEED_INSTEADOF_DURABILITY MDBX_OSX_WANNA_DURABILITY
|
|
|
|
#endif /* MDBX_OSX_SPEED_INSTEADOF_DURABILITY */
|
|
|
|
|
|
|
|
/* Controls checking PID against reuse DB environment after the fork() */
|
|
|
|
#ifndef MDBX_TXN_CHECKPID
|
|
|
|
#if defined(MADV_DONTFORK) || defined(_WIN32) || defined(_WIN64)
|
|
|
|
/* PID check could be ommited:
|
|
|
|
* - on Linux when madvise(MADV_DONTFORK) is available. i.e. after the fork()
|
|
|
|
* mapped pages will not be available for child process.
|
|
|
|
* - in Windows where fork() not available. */
|
|
|
|
#define MDBX_TXN_CHECKPID 0
|
|
|
|
#else
|
|
|
|
#define MDBX_TXN_CHECKPID 1
|
|
|
|
#endif
|
|
|
|
#define MDBX_TXN_CHECKPID_CONFIG "AUTO=" STRINGIFY(MDBX_TXN_CHECKPID)
|
|
|
|
#else
|
|
|
|
#define MDBX_TXN_CHECKPID_CONFIG STRINGIFY(MDBX_TXN_CHECKPID)
|
|
|
|
#endif /* MDBX_TXN_CHECKPID */
|
|
|
|
|
|
|
|
/* Controls checking transaction owner thread against misuse transactions from
|
|
|
|
* other threads. */
|
|
|
|
#ifndef MDBX_TXN_CHECKOWNER
|
|
|
|
#define MDBX_TXN_CHECKOWNER 1
|
|
|
|
#define MDBX_TXN_CHECKOWNER_CONFIG "AUTO=" STRINGIFY(MDBX_TXN_CHECKOWNER)
|
|
|
|
#else
|
|
|
|
#define MDBX_TXN_CHECKOWNER_CONFIG STRINGIFY(MDBX_TXN_CHECKOWNER)
|
|
|
|
#endif /* MDBX_TXN_CHECKOWNER */
|
|
|
|
|
|
|
|
/* Does a system have battery-backed Real-Time Clock or just a fake. */
|
|
|
|
#ifndef MDBX_TRUST_RTC
|
|
|
|
#if defined(__linux__) || defined(__gnu_linux__) || defined(__NetBSD__) || \
|
|
|
|
defined(__OpenBSD__)
|
|
|
|
#define MDBX_TRUST_RTC 0 /* a lot of embedded systems have a fake RTC */
|
|
|
|
#else
|
|
|
|
#define MDBX_TRUST_RTC 1
|
|
|
|
#endif
|
|
|
|
#define MDBX_TRUST_RTC_CONFIG "AUTO=" STRINGIFY(MDBX_TRUST_RTC)
|
|
|
|
#else
|
|
|
|
#define MDBX_TRUST_RTC_CONFIG STRINGIFY(MDBX_TRUST_RTC)
|
|
|
|
#endif /* MDBX_TRUST_RTC */
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define MDBX_LOCKING_WIN32FILES -1 /* Win32 File Locking API */
|
|
|
|
#define MDBX_LOCKING_SYSV 5 /* SystemV IPC semaphores */
|
|
|
|
#define MDBX_LOCKING_POSIX1988 1988 /* POSIX-1 Shared anonymous semaphores */
|
|
|
|
#define MDBX_LOCKING_POSIX2001 2001 /* POSIX-2001 Shared Mutexes */
|
|
|
|
#define MDBX_LOCKING_POSIX2008 2008 /* POSIX-2008 Robust Mutexes */
|
|
|
|
#define MDBX_LOCKING_BENAPHORE 1995 /* BeOS Benaphores, aka Futexes */
|
|
|
|
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
|
|
|
#define MDBX_LOCKING MDBX_LOCKING_WIN32FILES
|
|
|
|
#else
|
|
|
|
#ifndef MDBX_LOCKING
|
|
|
|
#if defined(_POSIX_THREAD_PROCESS_SHARED) && \
|
|
|
|
_POSIX_THREAD_PROCESS_SHARED >= 200112L && !defined(__FreeBSD__)
|
|
|
|
|
|
|
|
/* Some platforms define the EOWNERDEAD error code even though they
|
|
|
|
* don't support Robust Mutexes. If doubt compile with -MDBX_LOCKING=2001. */
|
|
|
|
#if defined(EOWNERDEAD) && _POSIX_THREAD_PROCESS_SHARED >= 200809L && \
|
2020-04-13 22:46:55 +03:00
|
|
|
((defined(_POSIX_THREAD_ROBUST_PRIO_INHERIT) && \
|
|
|
|
_POSIX_THREAD_ROBUST_PRIO_INHERIT > 0) || \
|
|
|
|
(defined(_POSIX_THREAD_ROBUST_PRIO_PROTECT) && \
|
|
|
|
_POSIX_THREAD_ROBUST_PRIO_PROTECT > 0) || \
|
2019-11-13 20:14:17 +03:00
|
|
|
defined(PTHREAD_MUTEX_ROBUST) || defined(PTHREAD_MUTEX_ROBUST_NP)) && \
|
|
|
|
(!defined(__GLIBC__) || \
|
|
|
|
__GLIBC_PREREQ(2, 10) /* troubles with Robust mutexes before 2.10 */)
|
|
|
|
#define MDBX_LOCKING MDBX_LOCKING_POSIX2008
|
|
|
|
#else
|
|
|
|
#define MDBX_LOCKING MDBX_LOCKING_POSIX2001
|
|
|
|
#endif
|
|
|
|
#elif defined(__sun) || defined(__SVR4) || defined(__svr4__)
|
|
|
|
#define MDBX_LOCKING MDBX_LOCKING_POSIX1988
|
|
|
|
#else
|
|
|
|
#define MDBX_LOCKING MDBX_LOCKING_SYSV
|
|
|
|
#endif
|
|
|
|
#define MDBX_LOCKING_CONFIG "AUTO=" STRINGIFY(MDBX_LOCKING)
|
|
|
|
#else
|
|
|
|
#define MDBX_LOCKING_CONFIG STRINGIFY(MDBX_LOCKING)
|
|
|
|
#endif /* MDBX_LOCKING */
|
|
|
|
#endif /* !Windows */
|
|
|
|
|
|
|
|
#ifndef MDBX_USE_OFDLOCKS
|
|
|
|
#if defined(F_OFD_SETLK) && defined(F_OFD_SETLKW) && defined(F_OFD_GETLK) && \
|
|
|
|
!defined(MDBX_SAFE4QEMU) && \
|
|
|
|
!defined(__sun) /* OFD-lock are broken on Solaris */
|
|
|
|
#define MDBX_USE_OFDLOCKS 1
|
|
|
|
#else
|
|
|
|
#define MDBX_USE_OFDLOCKS 0
|
|
|
|
#endif
|
|
|
|
#define MDBX_USE_OFDLOCKS_CONFIG "AUTO=" STRINGIFY(MDBX_USE_OFDLOCKS)
|
|
|
|
#else
|
|
|
|
#define MDBX_USE_OFDLOCKS_CONFIG STRINGIFY(MDBX_USE_OFDLOCKS)
|
|
|
|
#endif /* MDBX_USE_OFDLOCKS */
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2019-11-13 22:12:09 +03:00
|
|
|
#ifndef MDBX_CPU_WRITEBACK_INCOHERENT
|
2019-11-13 20:14:17 +03:00
|
|
|
#if defined(__ia32__) || defined(__e2k__) || defined(__hppa) || \
|
|
|
|
defined(__hppa__)
|
2019-11-13 22:12:09 +03:00
|
|
|
#define MDBX_CPU_WRITEBACK_INCOHERENT 0
|
2019-11-13 20:14:17 +03:00
|
|
|
#else
|
2019-11-13 22:12:09 +03:00
|
|
|
#define MDBX_CPU_WRITEBACK_INCOHERENT 1
|
2019-11-13 20:14:17 +03:00
|
|
|
#endif
|
2019-11-13 22:12:09 +03:00
|
|
|
#endif /* MDBX_CPU_WRITEBACK_INCOHERENT */
|
2019-11-13 20:14:17 +03:00
|
|
|
|
2019-11-13 22:12:09 +03:00
|
|
|
#ifndef MDBX_MMAP_INCOHERENT_FILE_WRITE
|
|
|
|
#ifdef __OpenBSD__
|
|
|
|
#define MDBX_MMAP_INCOHERENT_FILE_WRITE 1
|
|
|
|
#else
|
|
|
|
#define MDBX_MMAP_INCOHERENT_FILE_WRITE 0
|
|
|
|
#endif
|
|
|
|
#endif /* MDBX_MMAP_INCOHERENT_FILE_WRITE */
|
|
|
|
|
|
|
|
#ifndef MDBX_MMAP_INCOHERENT_CPU_CACHE
|
2019-11-13 20:14:17 +03:00
|
|
|
#if defined(__mips) || defined(__mips__) || defined(__mips64) || \
|
|
|
|
defined(__mips64__) || defined(_M_MRX000) || defined(_MIPS_) || \
|
|
|
|
defined(__MWERKS__) || defined(__sgi)
|
|
|
|
/* MIPS has cache coherency issues. */
|
2019-11-13 22:12:09 +03:00
|
|
|
#define MDBX_MMAP_INCOHERENT_CPU_CACHE 1
|
2019-11-13 20:14:17 +03:00
|
|
|
#else
|
|
|
|
/* LY: assume no relevant mmap/dcache issues. */
|
2019-11-13 22:12:09 +03:00
|
|
|
#define MDBX_MMAP_INCOHERENT_CPU_CACHE 0
|
2019-11-13 20:14:17 +03:00
|
|
|
#endif
|
2019-11-13 22:12:09 +03:00
|
|
|
#endif /* MDBX_MMAP_INCOHERENT_CPU_CACHE */
|
2019-11-13 20:14:17 +03:00
|
|
|
|
|
|
|
#ifndef MDBX_64BIT_ATOMIC
|
|
|
|
#if MDBX_WORDBITS >= 64
|
|
|
|
#define MDBX_64BIT_ATOMIC 1
|
|
|
|
#else
|
|
|
|
#define MDBX_64BIT_ATOMIC 0
|
|
|
|
#endif
|
|
|
|
#define MDBX_64BIT_ATOMIC_CONFIG "AUTO=" STRINGIFY(MDBX_64BIT_ATOMIC)
|
|
|
|
#else
|
|
|
|
#define MDBX_64BIT_ATOMIC_CONFIG STRINGIFY(MDBX_64BIT_ATOMIC)
|
|
|
|
#endif /* MDBX_64BIT_ATOMIC */
|
|
|
|
|
|
|
|
#ifndef MDBX_64BIT_CAS
|
|
|
|
#if defined(ATOMIC_LLONG_LOCK_FREE)
|
|
|
|
#if ATOMIC_LLONG_LOCK_FREE > 1
|
|
|
|
#define MDBX_64BIT_CAS 1
|
|
|
|
#else
|
|
|
|
#define MDBX_64BIT_CAS 0
|
|
|
|
#endif
|
|
|
|
#elif defined(__GCC_ATOMIC_LLONG_LOCK_FREE)
|
|
|
|
#if __GCC_ATOMIC_LLONG_LOCK_FREE > 1
|
|
|
|
#define MDBX_64BIT_CAS 1
|
|
|
|
#else
|
|
|
|
#define MDBX_64BIT_CAS 0
|
|
|
|
#endif
|
|
|
|
#elif defined(__CLANG_ATOMIC_LLONG_LOCK_FREE)
|
|
|
|
#if __CLANG_ATOMIC_LLONG_LOCK_FREE > 1
|
|
|
|
#define MDBX_64BIT_CAS 1
|
|
|
|
#else
|
|
|
|
#define MDBX_64BIT_CAS 0
|
|
|
|
#endif
|
|
|
|
#elif defined(_MSC_VER) || defined(__APPLE__)
|
|
|
|
#define MDBX_64BIT_CAS 1
|
|
|
|
#else
|
|
|
|
#define MDBX_64BIT_CAS MDBX_64BIT_ATOMIC
|
|
|
|
#endif
|
|
|
|
#define MDBX_64BIT_CAS_CONFIG "AUTO=" STRINGIFY(MDBX_64BIT_CAS)
|
|
|
|
#else
|
|
|
|
#define MDBX_64BIT_CAS_CONFIG STRINGIFY(MDBX_64BIT_CAS)
|
|
|
|
#endif /* MDBX_64BIT_CAS */
|
|
|
|
|
|
|
|
#if !defined(MDBX_UNALIGNED_OK)
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#define MDBX_UNALIGNED_OK 1 /* avoid MSVC misoptimization */
|
|
|
|
#elif __CLANG_PREREQ(5, 0) || __GNUC_PREREQ(5, 0)
|
|
|
|
#define MDBX_UNALIGNED_OK 0 /* expecting optimization is well done */
|
|
|
|
#elif (defined(__ia32__) || defined(__ARM_FEATURE_UNALIGNED)) && \
|
|
|
|
!defined(__ALIGNED__)
|
|
|
|
#define MDBX_UNALIGNED_OK 1
|
|
|
|
#else
|
|
|
|
#define MDBX_UNALIGNED_OK 0
|
|
|
|
#endif
|
|
|
|
#endif /* MDBX_UNALIGNED_OK */
|
|
|
|
|
|
|
|
#ifndef MDBX_CACHELINE_SIZE
|
|
|
|
#if defined(SYSTEM_CACHE_ALIGNMENT_SIZE)
|
|
|
|
#define MDBX_CACHELINE_SIZE SYSTEM_CACHE_ALIGNMENT_SIZE
|
|
|
|
#elif defined(__ia64__) || defined(__ia64) || defined(_M_IA64)
|
|
|
|
#define MDBX_CACHELINE_SIZE 128
|
|
|
|
#else
|
|
|
|
#define MDBX_CACHELINE_SIZE 64
|
|
|
|
#endif
|
|
|
|
#endif /* MDBX_CACHELINE_SIZE */
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*******************************************************************************
|
|
|
|
******************************************************************************/
|