mirror of
https://github.com/isar/libmdbx.git
synced 2024-12-30 02:24:14 +08:00
mdbx++: enables C++ API for amalgamated source code.
Change-Id: Ie73f32ee6b9a565eee69fa7267798a0fd67db4b0
This commit is contained in:
parent
cd4caeb03d
commit
6c70a7fe11
@ -24,6 +24,9 @@ LD ?= ld
|
||||
MDBX_OPTIONS ?= -DNDEBUG=1
|
||||
CFLAGS ?= -O2 -g -Wall -Werror -Wextra -Wpedantic -ffunction-sections -fPIC -fvisibility=hidden -std=gnu11 -pthread -Wno-error=attributes $(CFLAGS_EXTRA)
|
||||
# -Wno-tautological-compare
|
||||
CXX ?= g++
|
||||
CXXSTD ?= $(shell PROBE=$$([ -f mdbx.c++ ] && echo mdbx.c++ || echo src/mdbx.c++); for std in gnu++20 c++20 gnu++2a c++2a gnu++17 c++17 gnu++14 c++14 gnu+11 c++11; do $(CXX) -std=$${std} -c $${PROBE} -o /dev/null 2>/dev/null >/dev/null && echo "-std=$${std}" && exit; done)
|
||||
CXXFLAGS:= $(CXXSTD) $(filter-out -std=gnu11,$(CFLAGS))
|
||||
|
||||
# HINT: Try append '--no-as-needed,-lrt' for ability to built with modern glibc, but then run with the old.
|
||||
LIBS ?= $(shell uname | grep -qi SunOS && echo "-lkstat") $(shell uname | grep -qi -e Darwin -e OpenBSD || echo "-lrt") $(shell uname | grep -qi Windows && echo "-lntdll")
|
||||
@ -132,9 +135,6 @@ TEST_ITER := $(shell $(uname2titer))
|
||||
TEST_SRC := test/osal-$(TEST_OSAL).cc $(filter-out $(wildcard test/osal-*.cc), $(wildcard test/*.cc))
|
||||
TEST_INC := $(wildcard test/*.h)
|
||||
TEST_OBJ := $(patsubst %.cc,%.o,$(TEST_SRC))
|
||||
CXX ?= g++
|
||||
CXXSTD ?= $(shell $(CXX) -std=c++17 -c test/test.cc -o /dev/null 2>/dev/null && echo -std=c++17 || echo -std=c++11)
|
||||
CXXFLAGS := $(CXXSTD) $(filter-out -std=gnu11,$(CFLAGS))
|
||||
TAR ?= $(shell which gnu-tar || echo tar)
|
||||
ZIP ?= $(shell which zip || echo "echo 'Please install zip'")
|
||||
CLANG_FORMAT ?= $(shell (which clang-format-12 || which clang-format-11 || which clang-format-10 || which clang-format) 2>/dev/null)
|
||||
|
3
mdbx.h++
3
mdbx.h++
@ -33,7 +33,6 @@
|
||||
#include <cassert> // for assert()
|
||||
#include <cstring> // for std::strlen, str:memcmp
|
||||
#include <exception> // for std::exception_ptr
|
||||
#include <memory> // for std::uniq_ptr
|
||||
#include <ostream> // for std::ostream
|
||||
#include <sstream> // for std::ostringstream
|
||||
#include <stdexcept> // for std::invalid_argument
|
||||
@ -2220,7 +2219,7 @@ public:
|
||||
/// pages) in bytes.
|
||||
size_t size_current() const {
|
||||
assert(is_readwrite());
|
||||
return get_info().txn_space_dirty;
|
||||
return size_t(get_info().txn_space_dirty);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -422,7 +422,7 @@ typedef sem_t mdbx_ipclock_t;
|
||||
#error "FIXME"
|
||||
#endif /* MDBX_LOCKING */
|
||||
|
||||
#if MDBX_LOCKING > MDBX_LOCKING_SYSV
|
||||
#if MDBX_LOCKING > MDBX_LOCKING_SYSV && !defined(__cplusplus)
|
||||
MDBX_INTERNAL_FUNC int mdbx_ipclock_stub(mdbx_ipclock_t *ipc);
|
||||
MDBX_INTERNAL_FUNC int mdbx_ipclock_destroy(mdbx_ipclock_t *ipc);
|
||||
#endif /* MDBX_LOCKING */
|
||||
@ -1027,6 +1027,7 @@ struct MDBX_env {
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifndef __cplusplus
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Debug and Logging stuff */
|
||||
|
||||
@ -1206,6 +1207,17 @@ MDBX_INTERNAL_FUNC void mdbx_rthc_global_init(void);
|
||||
MDBX_INTERNAL_FUNC void mdbx_rthc_global_dtor(void);
|
||||
MDBX_INTERNAL_FUNC void mdbx_rthc_thread_dtor(void *ptr);
|
||||
|
||||
static __maybe_unused __inline void mdbx_jitter4testing(bool tiny) {
|
||||
#if MDBX_DEBUG
|
||||
if (MDBX_DBG_JITTER & mdbx_runtime_flags)
|
||||
mdbx_osal_jitter(tiny);
|
||||
#else
|
||||
(void)tiny;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* !__cplusplus */
|
||||
|
||||
#define MDBX_IS_ERROR(rc) \
|
||||
((rc) != MDBX_RESULT_TRUE && (rc) != MDBX_RESULT_FALSE)
|
||||
|
||||
@ -1360,15 +1372,6 @@ pgno_sub(pgno_t base, pgno_t subtrahend) {
|
||||
return (subtrahend < base - MIN_PAGENO) ? base - subtrahend : MIN_PAGENO;
|
||||
}
|
||||
|
||||
static __maybe_unused __inline void mdbx_jitter4testing(bool tiny) {
|
||||
#if MDBX_DEBUG
|
||||
if (MDBX_DBG_JITTER & mdbx_runtime_flags)
|
||||
mdbx_osal_jitter(tiny);
|
||||
#else
|
||||
(void)tiny;
|
||||
#endif
|
||||
}
|
||||
|
||||
__nothrow_const_function static __always_inline __maybe_unused bool
|
||||
is_powerof2(size_t x) {
|
||||
return (x & (x - 1)) == 0;
|
||||
|
@ -12,7 +12,7 @@
|
||||
* <http://www.OpenLDAP.org/license.html>. */
|
||||
|
||||
//
|
||||
// Non-inline part of the libmdbx C++ API (preliminary draft)
|
||||
// Non-inline part of the libmdbx C++ API (preliminary)
|
||||
//
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@ -25,7 +25,7 @@
|
||||
#include "internals.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cctype> // for isxdigit()
|
||||
#include <cctype> // for isxdigit(), etc
|
||||
#include <system_error>
|
||||
|
||||
#if defined(__has_include) && __has_include(<version>)
|
||||
|
95
src/osal.h
95
src/osal.h
@ -409,6 +409,55 @@ typedef pthread_mutex_t mdbx_fastmutex_t;
|
||||
#endif
|
||||
#endif /* __BYTE_ORDER__ || __ORDER_LITTLE_ENDIAN__ || __ORDER_BIG_ENDIAN__ */
|
||||
|
||||
/* Get the size of a memory page for the system.
|
||||
* This is the basic size that the platform's memory manager uses, and is
|
||||
* fundamental to the use of memory-mapped files. */
|
||||
__nothrow_const_function static __maybe_unused __inline size_t
|
||||
mdbx_syspagesize(void) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
SYSTEM_INFO si;
|
||||
GetSystemInfo(&si);
|
||||
return si.dwPageSize;
|
||||
#else
|
||||
return sysconf(_SC_PAGE_SIZE);
|
||||
#endif
|
||||
}
|
||||
|
||||
typedef struct mdbx_mmap_param {
|
||||
union {
|
||||
void *address;
|
||||
uint8_t *dxb;
|
||||
struct MDBX_lockinfo *lck;
|
||||
};
|
||||
mdbx_filehandle_t fd;
|
||||
size_t limit; /* mapping length, but NOT a size of file nor DB */
|
||||
size_t current; /* mapped region size, i.e. the size of file and DB */
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
uint64_t filesize /* in-process cache of a file size. */;
|
||||
#endif
|
||||
#ifdef MDBX_OSAL_SECTION
|
||||
MDBX_OSAL_SECTION section;
|
||||
#endif
|
||||
} mdbx_mmap_t;
|
||||
|
||||
typedef union bin128 {
|
||||
__anonymous_struct_extension__ struct { uint64_t x, y; };
|
||||
__anonymous_struct_extension__ struct { uint32_t a, b, c, d; };
|
||||
} bin128_t;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
typedef union MDBX_srwlock {
|
||||
struct {
|
||||
long volatile readerCount;
|
||||
long volatile writerCount;
|
||||
};
|
||||
RTL_SRWLOCK native;
|
||||
} MDBX_srwlock;
|
||||
#endif /* Windows */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern void mdbx_osal_jitter(bool tiny);
|
||||
#else
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Memory/Compiler barriers, cache coherence */
|
||||
|
||||
@ -508,20 +557,6 @@ MDBX_INTERNAL_VAR bool
|
||||
mdbx_RunningOnWSL /* Windows Subsystem for Linux is mad and trouble-full */;
|
||||
#endif /* Linux */
|
||||
|
||||
/* Get the size of a memory page for the system.
|
||||
* This is the basic size that the platform's memory manager uses, and is
|
||||
* fundamental to the use of memory-mapped files. */
|
||||
__nothrow_const_function static __maybe_unused __inline size_t
|
||||
mdbx_syspagesize(void) {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
SYSTEM_INFO si;
|
||||
GetSystemInfo(&si);
|
||||
return si.dwPageSize;
|
||||
#else
|
||||
return sysconf(_SC_PAGE_SIZE);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef mdbx_strdup
|
||||
LIBMDBX_API char *mdbx_strdup(const char *str);
|
||||
#endif
|
||||
@ -601,23 +636,6 @@ MDBX_INTERNAL_FUNC int mdbx_closefile(mdbx_filehandle_t fd);
|
||||
MDBX_INTERNAL_FUNC int mdbx_removefile(const char *pathname);
|
||||
MDBX_INTERNAL_FUNC int mdbx_is_pipe(mdbx_filehandle_t fd);
|
||||
|
||||
typedef struct mdbx_mmap_param {
|
||||
union {
|
||||
void *address;
|
||||
uint8_t *dxb;
|
||||
struct MDBX_lockinfo *lck;
|
||||
};
|
||||
mdbx_filehandle_t fd;
|
||||
size_t limit; /* mapping length, but NOT a size of file nor DB */
|
||||
size_t current; /* mapped region size, i.e. the size of file and DB */
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
uint64_t filesize /* in-process cache of a file size. */;
|
||||
#endif
|
||||
#ifdef MDBX_OSAL_SECTION
|
||||
MDBX_OSAL_SECTION section;
|
||||
#endif
|
||||
} mdbx_mmap_t;
|
||||
|
||||
#define MMAP_OPTION_TRUNCATE 1
|
||||
#define MMAP_OPTION_SEMAPHORE 2
|
||||
MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
|
||||
@ -668,11 +686,6 @@ MDBX_INTERNAL_FUNC uint64_t
|
||||
mdbx_osal_16dot16_to_monotime(uint32_t seconds_16dot16);
|
||||
MDBX_INTERNAL_FUNC uint32_t mdbx_osal_monotime_to_16dot16(uint64_t monotime);
|
||||
|
||||
typedef union bin128 {
|
||||
__anonymous_struct_extension__ struct { uint64_t x, y; };
|
||||
__anonymous_struct_extension__ struct { uint32_t a, b, c, d; };
|
||||
} bin128_t;
|
||||
|
||||
MDBX_INTERNAL_FUNC bin128_t mdbx_osal_bootid(void);
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* lck stuff */
|
||||
@ -782,14 +795,6 @@ MDBX_INTERNAL_FUNC int mdbx_rpid_check(MDBX_env *env, uint32_t pid);
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
typedef union MDBX_srwlock {
|
||||
struct {
|
||||
long volatile readerCount;
|
||||
long volatile writerCount;
|
||||
};
|
||||
RTL_SRWLOCK native;
|
||||
} MDBX_srwlock;
|
||||
|
||||
typedef void(WINAPI *MDBX_srwlock_function)(MDBX_srwlock *);
|
||||
MDBX_INTERNAL_VAR MDBX_srwlock_function mdbx_srwlock_Init,
|
||||
mdbx_srwlock_AcquireShared, mdbx_srwlock_ReleaseShared,
|
||||
@ -909,6 +914,8 @@ static __inline bool mdbx_RunningUnderWine(void) {
|
||||
#error FIXME atomic-ops
|
||||
#endif
|
||||
|
||||
#endif /* !__cplusplus */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1900
|
||||
|
Loading…
x
Reference in New Issue
Block a user