mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 00:24:13 +08:00
mdbx: reformat by clang-format 6.0 (cosmetic).
This commit is contained in:
parent
b0550b38b8
commit
9db090087e
26
mdbx.h
26
mdbx.h
@ -340,33 +340,33 @@ typedef int(MDBX_cmp_func)(const MDBX_val *a, const MDBX_val *b);
|
||||
typedef enum MDBX_cursor_op {
|
||||
MDBX_FIRST, /* Position at first key/data item */
|
||||
MDBX_FIRST_DUP, /* MDBX_DUPSORT-only: Position at first data item
|
||||
* of current key. */
|
||||
* of current key. */
|
||||
MDBX_GET_BOTH, /* MDBX_DUPSORT-only: Position at key/data pair. */
|
||||
MDBX_GET_BOTH_RANGE, /* MDBX_DUPSORT-only: position at key, nearest data. */
|
||||
MDBX_GET_CURRENT, /* Return key/data at current cursor position */
|
||||
MDBX_GET_MULTIPLE, /* MDBX_DUPFIXED-only: Return key and up to a page of
|
||||
* duplicate data items from current cursor position.
|
||||
* Move cursor to prepare for MDBX_NEXT_MULTIPLE.*/
|
||||
* duplicate data items from current cursor position.
|
||||
* Move cursor to prepare for MDBX_NEXT_MULTIPLE.*/
|
||||
MDBX_LAST, /* Position at last key/data item */
|
||||
MDBX_LAST_DUP, /* MDBX_DUPSORT-only: Position at last data item
|
||||
* of current key. */
|
||||
* of current key. */
|
||||
MDBX_NEXT, /* Position at next data item */
|
||||
MDBX_NEXT_DUP, /* MDBX_DUPSORT-only: Position at next data item
|
||||
* of current key. */
|
||||
* of current key. */
|
||||
MDBX_NEXT_MULTIPLE, /* MDBX_DUPFIXED-only: Return key and up to a page of
|
||||
* duplicate data items from next cursor position.
|
||||
* Move cursor to prepare for MDBX_NEXT_MULTIPLE. */
|
||||
* duplicate data items from next cursor position.
|
||||
* Move cursor to prepare for MDBX_NEXT_MULTIPLE. */
|
||||
MDBX_NEXT_NODUP, /* Position at first data item of next key */
|
||||
MDBX_PREV, /* Position at previous data item */
|
||||
MDBX_PREV_DUP, /* MDBX_DUPSORT-only: Position at previous data item
|
||||
* of current key. */
|
||||
* of current key. */
|
||||
MDBX_PREV_NODUP, /* Position at last data item of previous key */
|
||||
MDBX_SET, /* Position at specified key */
|
||||
MDBX_SET_KEY, /* Position at specified key, return both key and data */
|
||||
MDBX_SET_RANGE, /* Position at first key greater than or equal to
|
||||
* specified key. */
|
||||
* specified key. */
|
||||
MDBX_PREV_MULTIPLE /* MDBX_DUPFIXED-only: Position at previous page and
|
||||
* return key and up to a page of duplicate data items. */
|
||||
* return key and up to a page of duplicate data items. */
|
||||
} MDBX_cursor_op;
|
||||
|
||||
/* Return Codes
|
||||
@ -966,7 +966,7 @@ LIBMDBX_API int mdbx_env_set_assert(MDBX_env *env, MDBX_assert_func *func);
|
||||
* Returns A non-zero error value on failure and 0 on success, some
|
||||
* possible errors are:
|
||||
* - MDBX_PANIC - a fatal error occurred earlier and the environment
|
||||
* must be shut down.
|
||||
* must be shut down.
|
||||
* - MDBX_MAP_RESIZED - another process wrote data beyond this MDBX_env's
|
||||
* mapsize and this environment's map must be resized
|
||||
* as well. See mdbx_env_set_mapsize().
|
||||
@ -1637,7 +1637,9 @@ typedef int MDBX_pgvisitor_func(uint64_t pgno, unsigned pgnumber, void *ctx,
|
||||
LIBMDBX_API int mdbx_env_pgwalk(MDBX_txn *txn, MDBX_pgvisitor_func *visitor,
|
||||
void *ctx);
|
||||
|
||||
typedef struct mdbx_canary { uint64_t x, y, z, v; } mdbx_canary;
|
||||
typedef struct mdbx_canary {
|
||||
uint64_t x, y, z, v;
|
||||
} mdbx_canary;
|
||||
|
||||
LIBMDBX_API int mdbx_canary_put(MDBX_txn *txn, const mdbx_canary *canary);
|
||||
LIBMDBX_API int mdbx_canary_get(MDBX_txn *txn, mdbx_canary *canary);
|
||||
|
26
src/bits.h
26
src/bits.h
@ -367,19 +367,19 @@ typedef struct MDBX_page {
|
||||
#define PAGEHDRSZ ((unsigned)offsetof(MDBX_page, mp_data))
|
||||
|
||||
/* The maximum size of a database page.
|
||||
*
|
||||
* It is 64K, but value-PAGEHDRSZ must fit in MDBX_page.mp_upper.
|
||||
*
|
||||
* MDBX will use database pages < OS pages if needed.
|
||||
* That causes more I/O in write transactions: The OS must
|
||||
* know (read) the whole page before writing a partial page.
|
||||
*
|
||||
* Note that we don't currently support Huge pages. On Linux,
|
||||
* regular data files cannot use Huge pages, and in general
|
||||
* Huge pages aren't actually pageable. We rely on the OS
|
||||
* demand-pager to read our data and page it out when memory
|
||||
* pressure from other processes is high. So until OSs have
|
||||
* actual paging support for Huge pages, they're not viable. */
|
||||
*
|
||||
* It is 64K, but value-PAGEHDRSZ must fit in MDBX_page.mp_upper.
|
||||
*
|
||||
* MDBX will use database pages < OS pages if needed.
|
||||
* That causes more I/O in write transactions: The OS must
|
||||
* know (read) the whole page before writing a partial page.
|
||||
*
|
||||
* Note that we don't currently support Huge pages. On Linux,
|
||||
* regular data files cannot use Huge pages, and in general
|
||||
* Huge pages aren't actually pageable. We rely on the OS
|
||||
* demand-pager to read our data and page it out when memory
|
||||
* pressure from other processes is high. So until OSs have
|
||||
* actual paging support for Huge pages, they're not viable. */
|
||||
#define MAX_PAGESIZE 0x10000u
|
||||
#define MIN_PAGESIZE 512u
|
||||
|
||||
|
@ -127,8 +127,9 @@ int mdbx_txn_lock(MDBX_env *env, bool dontwait) {
|
||||
EnterCriticalSection(&env->me_windowsbug_lock);
|
||||
}
|
||||
|
||||
if (flock(env->me_fd, dontwait ? (LCK_EXCLUSIVE | LCK_DONTWAIT)
|
||||
: (LCK_EXCLUSIVE | LCK_WAITFOR),
|
||||
if (flock(env->me_fd,
|
||||
dontwait ? (LCK_EXCLUSIVE | LCK_DONTWAIT)
|
||||
: (LCK_EXCLUSIVE | LCK_WAITFOR),
|
||||
LCK_BODY))
|
||||
return MDBX_SUCCESS;
|
||||
int rc = GetLastError();
|
||||
@ -353,7 +354,7 @@ static int internal_seize_lck(HANDLE lfd) {
|
||||
"?-E(middle) >> S-E(locked)", rc);
|
||||
|
||||
/* 8) now on S-E (locked) or still on ?-E (middle),
|
||||
* transite to S-? (used) or ?-? (free) */
|
||||
* transite to S-? (used) or ?-? (free) */
|
||||
if (!funlock(lfd, LCK_UPPER))
|
||||
mdbx_panic("%s(%s) failed: errcode %u", mdbx_func_,
|
||||
"X-E(locked/middle) >> X-?(used/free)", GetLastError());
|
||||
|
35
src/mdbx.c
35
src/mdbx.c
@ -42,8 +42,8 @@
|
||||
int __hot mdbx_e2k_memcmp_bug_workaround(const void *s1, const void *s2,
|
||||
size_t n) {
|
||||
if (unlikely(n > 42
|
||||
/* LY: align followed access if reasonable possible */ &&
|
||||
(((uintptr_t)s1) & 7) != 0 &&
|
||||
/* LY: align followed access if reasonable possible */
|
||||
&& (((uintptr_t)s1) & 7) != 0 &&
|
||||
(((uintptr_t)s1) & 7) == (((uintptr_t)s2) & 7))) {
|
||||
if (((uintptr_t)s1) & 1) {
|
||||
const int diff = *(uint8_t *)s1 - *(uint8_t *)s2;
|
||||
@ -4733,9 +4733,8 @@ static int mdbx_sync_locked(MDBX_env *env, unsigned flags,
|
||||
mdbx_assert(env, !mdbx_meta_eq(env, pending, meta2));
|
||||
|
||||
mdbx_assert(env, ((env->me_flags ^ flags) & MDBX_WRITEMAP) == 0);
|
||||
mdbx_ensure(env,
|
||||
target == head ||
|
||||
mdbx_meta_txnid_stable(env, target) < pending->mm_txnid_a);
|
||||
mdbx_ensure(env, target == head || mdbx_meta_txnid_stable(env, target) <
|
||||
pending->mm_txnid_a);
|
||||
if (env->me_flags & MDBX_WRITEMAP) {
|
||||
mdbx_jitter4testing(true);
|
||||
if (likely(target != head)) {
|
||||
@ -5835,9 +5834,9 @@ int __cold mdbx_env_open_ex(MDBX_env *env, const char *path, unsigned flags,
|
||||
if ((flags & MDBX_RDONLY) == 0) {
|
||||
MDBX_txn *txn;
|
||||
int tsize = sizeof(MDBX_txn),
|
||||
size = tsize +
|
||||
env->me_maxdbs * (sizeof(MDBX_db) + sizeof(MDBX_cursor *) +
|
||||
sizeof(unsigned) + 1);
|
||||
size =
|
||||
tsize + env->me_maxdbs * (sizeof(MDBX_db) + sizeof(MDBX_cursor *) +
|
||||
sizeof(unsigned) + 1);
|
||||
if ((env->me_pbuf = calloc(1, env->me_psize)) && (txn = calloc(1, size))) {
|
||||
txn->mt_dbs = (MDBX_db *)((char *)txn + tsize);
|
||||
txn->mt_cursors = (MDBX_cursor **)(txn->mt_dbs + env->me_maxdbs);
|
||||
@ -6085,7 +6084,7 @@ static int __hot mdbx_cmp_int_ua(const MDBX_val *a, const MDBX_val *b) {
|
||||
} while (pa != a->iov_base);
|
||||
return diff;
|
||||
}
|
||||
#else /* __BYTE_ORDER__ */
|
||||
#else /* __BYTE_ORDER__ */
|
||||
return memcmp(a->iov_base, b->iov_base, a->iov_len);
|
||||
#endif /* __BYTE_ORDER__ */
|
||||
#endif /* UNALIGNED_OK */
|
||||
@ -6315,7 +6314,7 @@ static int mdbx_page_get(MDBX_cursor *mc, pgno_t pgno, MDBX_page **ret,
|
||||
|
||||
mapped:
|
||||
p = pgno2page(env, pgno);
|
||||
/* TODO: check p->mp_validator here */
|
||||
/* TODO: check p->mp_validator here */
|
||||
|
||||
done:
|
||||
*ret = p;
|
||||
@ -10038,9 +10037,8 @@ int mdbx_put(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *data,
|
||||
if (unlikely(!TXN_DBI_EXIST(txn, dbi, DB_USRVALID)))
|
||||
return MDBX_EINVAL;
|
||||
|
||||
if (unlikely(flags &
|
||||
~(MDBX_NOOVERWRITE | MDBX_NODUPDATA | MDBX_RESERVE |
|
||||
MDBX_APPEND | MDBX_APPENDDUP | MDBX_CURRENT)))
|
||||
if (unlikely(flags & ~(MDBX_NOOVERWRITE | MDBX_NODUPDATA | MDBX_RESERVE |
|
||||
MDBX_APPEND | MDBX_APPENDDUP | MDBX_CURRENT)))
|
||||
return MDBX_EINVAL;
|
||||
|
||||
if (unlikely(txn->mt_flags & (MDBX_TXN_RDONLY | MDBX_TXN_BLOCKED)))
|
||||
@ -10680,9 +10678,9 @@ int __cold mdbx_env_info(MDBX_env *env, MDBX_envinfo *arg, size_t bytes) {
|
||||
}
|
||||
|
||||
static MDBX_cmp_func *mdbx_default_keycmp(unsigned flags) {
|
||||
return (flags & MDBX_REVERSEKEY) ? mdbx_cmp_memnr : (flags & MDBX_INTEGERKEY)
|
||||
? mdbx_cmp_int_a2
|
||||
: mdbx_cmp_memn;
|
||||
return (flags & MDBX_REVERSEKEY)
|
||||
? mdbx_cmp_memnr
|
||||
: (flags & MDBX_INTEGERKEY) ? mdbx_cmp_int_a2 : mdbx_cmp_memn;
|
||||
}
|
||||
|
||||
static MDBX_cmp_func *mdbx_default_datacmp(unsigned flags) {
|
||||
@ -11872,9 +11870,8 @@ int mdbx_replace(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key, MDBX_val *new_data,
|
||||
if (unlikely(!TXN_DBI_EXIST(txn, dbi, DB_USRVALID)))
|
||||
return MDBX_EINVAL;
|
||||
|
||||
if (unlikely(flags &
|
||||
~(MDBX_NOOVERWRITE | MDBX_NODUPDATA | MDBX_RESERVE |
|
||||
MDBX_APPEND | MDBX_APPENDDUP | MDBX_CURRENT)))
|
||||
if (unlikely(flags & ~(MDBX_NOOVERWRITE | MDBX_NODUPDATA | MDBX_RESERVE |
|
||||
MDBX_APPEND | MDBX_APPENDDUP | MDBX_CURRENT)))
|
||||
return MDBX_EINVAL;
|
||||
|
||||
if (unlikely(txn->mt_flags & (MDBX_TXN_RDONLY | MDBX_TXN_BLOCKED)))
|
||||
|
30
src/osal.c
30
src/osal.c
@ -837,13 +837,14 @@ int mdbx_mmap(int flags, mdbx_mmap_t *map, size_t size, size_t limit) {
|
||||
SectionSize.QuadPart = size;
|
||||
rc = NtCreateSection(
|
||||
&map->section,
|
||||
/* DesiredAccess */ (flags & MDBX_WRITEMAP)
|
||||
/* DesiredAccess */
|
||||
(flags & MDBX_WRITEMAP)
|
||||
? SECTION_QUERY | SECTION_MAP_READ | SECTION_EXTEND_SIZE |
|
||||
SECTION_MAP_WRITE
|
||||
: SECTION_QUERY | SECTION_MAP_READ | SECTION_EXTEND_SIZE,
|
||||
/* ObjectAttributes */ NULL, /* MaximumSize (InitialSize) */ &SectionSize,
|
||||
/* SectionPageProtection */ (flags & MDBX_RDONLY) ? PAGE_READONLY
|
||||
: PAGE_READWRITE,
|
||||
/* SectionPageProtection */
|
||||
(flags & MDBX_RDONLY) ? PAGE_READONLY : PAGE_READWRITE,
|
||||
/* AllocationAttributes */ SEC_RESERVE, map->fd);
|
||||
if (!NT_SUCCESS(rc))
|
||||
return ntstatus2errcode(rc);
|
||||
@ -856,8 +857,8 @@ int mdbx_mmap(int flags, mdbx_mmap_t *map, size_t size, size_t limit) {
|
||||
/* SectionOffset */ NULL, &ViewSize,
|
||||
/* InheritDisposition */ ViewUnmap,
|
||||
/* AllocationType */ (flags & MDBX_RDONLY) ? 0 : MEM_RESERVE,
|
||||
/* Win32Protect */ (flags & MDBX_WRITEMAP) ? PAGE_READWRITE
|
||||
: PAGE_READONLY);
|
||||
/* Win32Protect */
|
||||
(flags & MDBX_WRITEMAP) ? PAGE_READWRITE : PAGE_READONLY);
|
||||
if (!NT_SUCCESS(rc)) {
|
||||
NtClose(map->section);
|
||||
map->section = 0;
|
||||
@ -941,10 +942,10 @@ int mdbx_mresize(int flags, mdbx_mmap_t *map, size_t size, size_t limit) {
|
||||
}
|
||||
|
||||
/* Windows unable:
|
||||
* - shrink a mapped file;
|
||||
* - change size of mapped view;
|
||||
* - extend read-only mapping;
|
||||
* Therefore we should unmap/map entire section. */
|
||||
* - shrink a mapped file;
|
||||
* - change size of mapped view;
|
||||
* - extend read-only mapping;
|
||||
* Therefore we should unmap/map entire section. */
|
||||
status = NtUnmapViewOfSection(GetCurrentProcess(), map->address);
|
||||
if (!NT_SUCCESS(status))
|
||||
return ntstatus2errcode(status);
|
||||
@ -996,14 +997,15 @@ retry_file_and_section:
|
||||
SectionSize.QuadPart = size;
|
||||
status = NtCreateSection(
|
||||
&map->section,
|
||||
/* DesiredAccess */ (flags & MDBX_WRITEMAP)
|
||||
/* DesiredAccess */
|
||||
(flags & MDBX_WRITEMAP)
|
||||
? SECTION_QUERY | SECTION_MAP_READ | SECTION_EXTEND_SIZE |
|
||||
SECTION_MAP_WRITE
|
||||
: SECTION_QUERY | SECTION_MAP_READ | SECTION_EXTEND_SIZE,
|
||||
/* ObjectAttributes */ NULL,
|
||||
/* MaximumSize (InitialSize) */ &SectionSize,
|
||||
/* SectionPageProtection */ (flags & MDBX_RDONLY) ? PAGE_READONLY
|
||||
: PAGE_READWRITE,
|
||||
/* SectionPageProtection */
|
||||
(flags & MDBX_RDONLY) ? PAGE_READONLY : PAGE_READWRITE,
|
||||
/* AllocationAttributes */ SEC_RESERVE, map->fd);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
@ -1027,8 +1029,8 @@ retry_mapview:;
|
||||
/* SectionOffset */ NULL, &ViewSize,
|
||||
/* InheritDisposition */ ViewUnmap,
|
||||
/* AllocationType */ (flags & MDBX_RDONLY) ? 0 : MEM_RESERVE,
|
||||
/* Win32Protect */ (flags & MDBX_WRITEMAP) ? PAGE_READWRITE
|
||||
: PAGE_READONLY);
|
||||
/* Win32Protect */
|
||||
(flags & MDBX_WRITEMAP) ? PAGE_READWRITE : PAGE_READONLY);
|
||||
|
||||
if (!NT_SUCCESS(status)) {
|
||||
if (status == /* STATUS_CONFLICTING_ADDRESSES */ 0xC0000018 &&
|
||||
|
@ -143,8 +143,8 @@ static void readhdr(void) {
|
||||
lineno, (char *)dbuf.iov_base + STRLENOF("mapsize="));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else if (!strncmp(dbuf.iov_base, "maxreaders=",
|
||||
STRLENOF("maxreaders="))) {
|
||||
} else if (!strncmp(dbuf.iov_base,
|
||||
"maxreaders=", STRLENOF("maxreaders="))) {
|
||||
int i;
|
||||
ptr = memchr(dbuf.iov_base, '\n', dbuf.iov_len);
|
||||
if (ptr)
|
||||
|
@ -32,10 +32,10 @@
|
||||
#endif /* _MSC_VER (warnings) */
|
||||
|
||||
/* If you wish to build your application for a previous Windows platform,
|
||||
* include WinSDKVer.h and set the _WIN32_WINNT macro to the platform you
|
||||
* wish to support before including SDKDDKVer.h.
|
||||
*
|
||||
* TODO: #define _WIN32_WINNT WIN32_MUSTDIE */
|
||||
* include WinSDKVer.h and set the _WIN32_WINNT macro to the platform you
|
||||
* wish to support before including SDKDDKVer.h.
|
||||
*
|
||||
* TODO: #define _WIN32_WINNT WIN32_MUSTDIE */
|
||||
#include <SDKDDKVer.h>
|
||||
#endif /* WINDOWS */
|
||||
|
||||
|
@ -206,7 +206,7 @@ void local_suffix::pop() {
|
||||
|
||||
local_suffix::~local_suffix() { suffix.erase(trim_pos); }
|
||||
|
||||
} /* namespace log */
|
||||
} // namespace logging
|
||||
|
||||
void log_extra(const char *msg, ...) {
|
||||
if (logging::extra >= logging::level) {
|
||||
|
@ -70,7 +70,7 @@ public:
|
||||
~local_suffix();
|
||||
};
|
||||
|
||||
} /* namespace log */
|
||||
} // namespace logging
|
||||
|
||||
void __printf_args(1, 2) log_extra(const char *msg, ...);
|
||||
void __printf_args(1, 2) log_trace(const char *msg, ...);
|
||||
|
@ -122,9 +122,8 @@ int main(int argc, char *const argv[]) {
|
||||
if (argc < 2)
|
||||
failure("No parameters given\n");
|
||||
|
||||
if (argc == 2 &&
|
||||
strncmp(argv[1], global::thunk_param_prefix,
|
||||
strlen(global::thunk_param_prefix)) == 0)
|
||||
if (argc == 2 && strncmp(argv[1], global::thunk_param_prefix,
|
||||
strlen(global::thunk_param_prefix)) == 0)
|
||||
return test_execute(
|
||||
actor_config(argv[1] + strlen(global::thunk_param_prefix)))
|
||||
? EXIT_SUCCESS
|
||||
|
@ -169,7 +169,7 @@ typedef std::pair<HANDLE, actor_status> child;
|
||||
static std::unordered_map<mdbx_pid_t, child> childs;
|
||||
|
||||
static void ArgvQuote(std::string &CommandLine, const std::string &Argument,
|
||||
bool Force = false)
|
||||
bool Force = false)
|
||||
|
||||
/*++
|
||||
|
||||
|
@ -85,9 +85,9 @@ static void mdbx_logger(int type, const char *function, int line,
|
||||
level = logging::failure;
|
||||
}
|
||||
|
||||
if (logging::output(level, strncmp(function, "mdbx_", 5) == 0 ? "%s: "
|
||||
: "mdbx: %s: ",
|
||||
function))
|
||||
if (logging::output(
|
||||
level,
|
||||
strncmp(function, "mdbx_", 5) == 0 ? "%s: " : "mdbx: %s: ", function))
|
||||
logging::feed(msg, args);
|
||||
if (type & MDBX_DBG_ASSERT)
|
||||
abort();
|
||||
|
Loading…
x
Reference in New Issue
Block a user