mirror of
https://github.com/isar/libmdbx.git
synced 2024-10-30 23:39:19 +08:00
mdbx: fix MSVC 'padding' warnings, minor refine fields ordering.
This commit is contained in:
parent
1d702aa94f
commit
78ae12aa10
20
src/bits.h
20
src/bits.h
@ -52,6 +52,7 @@
|
||||
#pragma warning(disable : 4127) /* conditional expression is constant */
|
||||
#pragma warning(disable : 4324) /* 'xyz': structure was padded due to alignment specifier */
|
||||
#pragma warning(disable : 4310) /* cast truncates constant value */
|
||||
#pragma warning(disable : 4820) /* bytes padding added after data member for aligment */
|
||||
#endif /* _MSC_VER (warnings) */
|
||||
|
||||
#include "../mdbx.h"
|
||||
@ -362,11 +363,6 @@ typedef struct MDBX_page {
|
||||
|
||||
#define MAX_MAPSIZE ((sizeof(size_t) < 8) ? MAX_MAPSIZE32 : MAX_MAPSIZE64)
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4820) /* bytes padding added after data member \
|
||||
for aligment */
|
||||
#endif
|
||||
|
||||
/* The header for the reader table (a memory-mapped lock file). */
|
||||
typedef struct MDBX_lockinfo {
|
||||
/* Stamp identifying this as an MDBX file.
|
||||
@ -419,7 +415,7 @@ typedef struct MDBX_lockinfo {
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
#endif /* MSVC: Enable aligment */
|
||||
|
||||
#define MDBX_LOCKINFO_WHOLE_SIZE \
|
||||
((sizeof(MDBX_lockinfo) + MDBX_CACHELINE_SIZE - 1) & \
|
||||
@ -492,7 +488,7 @@ typedef struct MDBX_dbx {
|
||||
* Every operation requires a transaction handle. */
|
||||
struct MDBX_txn {
|
||||
#define MDBX_MT_SIGNATURE UINT32_C(0x93D53A31)
|
||||
uint32_t mt_signature;
|
||||
size_t mt_signature;
|
||||
MDBX_txn *mt_parent; /* parent of a nested txn */
|
||||
/* Nested txn under this txn, set together with flag MDBX_TXN_HAS_CHILD */
|
||||
MDBX_txn *mt_child;
|
||||
@ -568,8 +564,8 @@ struct MDBX_txn {
|
||||
* dirty/spilled pages. Thus commit(nested txn) has room to merge
|
||||
* dirtylist into mt_parent after freeing hidden mt_parent pages. */
|
||||
unsigned mt_dirtyroom;
|
||||
mdbx_canary mt_canary;
|
||||
mdbx_tid_t mt_owner; /* thread ID that owns this transaction */
|
||||
mdbx_canary mt_canary;
|
||||
};
|
||||
|
||||
/* Enough space for 2^32 nodes with minimum of 2 keys per node. I.e., plenty.
|
||||
@ -591,6 +587,8 @@ struct MDBX_cursor {
|
||||
#define MDBX_MC_READY4CLOSE UINT32_C(0x2817A047)
|
||||
#define MDBX_MC_WAIT4EOT UINT32_C(0x90E297A7)
|
||||
uint32_t mc_signature;
|
||||
/* The database handle this cursor operates on */
|
||||
MDBX_dbi mc_dbi;
|
||||
/* Next cursor on this DB in this txn */
|
||||
MDBX_cursor *mc_next;
|
||||
/* Backup of the original cursor if this cursor is a shadow */
|
||||
@ -599,8 +597,6 @@ struct MDBX_cursor {
|
||||
struct MDBX_xcursor *mc_xcursor;
|
||||
/* The transaction that owns this cursor */
|
||||
MDBX_txn *mc_txn;
|
||||
/* The database handle this cursor operates on */
|
||||
MDBX_dbi mc_dbi;
|
||||
/* The database record for this cursor */
|
||||
MDBX_db *mc_db;
|
||||
/* The database auxiliary record for this cursor */
|
||||
@ -661,7 +657,7 @@ typedef struct MDBX_pgstate {
|
||||
/* The database environment. */
|
||||
struct MDBX_env {
|
||||
#define MDBX_ME_SIGNATURE UINT32_C(0x9A899641)
|
||||
uint32_t me_signature;
|
||||
size_t me_signature;
|
||||
mdbx_filehandle_t me_fd; /* The main data file */
|
||||
mdbx_filehandle_t me_lfd; /* The lock file */
|
||||
#ifdef MDBX_OSAL_SECTION
|
||||
@ -685,6 +681,7 @@ struct MDBX_env {
|
||||
MDBX_dbi me_numdbs; /* number of DBs opened */
|
||||
MDBX_dbi me_maxdbs; /* size of the DB table */
|
||||
mdbx_pid_t me_pid; /* process ID of this env */
|
||||
mdbx_thread_key_t me_txkey; /* thread-key for readers */
|
||||
char *me_path; /* path to the DB files */
|
||||
char *me_map; /* the memory map of the data file */
|
||||
MDBX_lockinfo *me_lck; /* the memory map of the lock file, never NULL */
|
||||
@ -695,7 +692,6 @@ struct MDBX_env {
|
||||
MDBX_dbx *me_dbxs; /* array of static DB info */
|
||||
uint16_t *me_dbflags; /* array of flags from MDBX_db.md_flags */
|
||||
unsigned *me_dbiseqs; /* array of dbi sequence numbers */
|
||||
mdbx_thread_key_t me_txkey; /* thread-key for readers */
|
||||
volatile txnid_t *me_oldest; /* ID of oldest reader last time we looked */
|
||||
MDBX_pgstate me_pgstate; /* state of old pages from freeDB */
|
||||
#define me_last_reclaimed me_pgstate.mf_last_reclaimed
|
||||
|
12
src/mdbx.c
12
src/mdbx.c
@ -9088,13 +9088,13 @@ typedef struct mdbx_copy {
|
||||
char *mc_over[2];
|
||||
size_t mc_wlen[2];
|
||||
size_t mc_olen[2];
|
||||
pgno_t mc_next_pgno;
|
||||
mdbx_filehandle_t mc_fd;
|
||||
int mc_toggle; /* Buffer number in provider */
|
||||
int mc_new; /* (0-2 buffers to write) | (MDBX_EOF at end) */
|
||||
volatile int mc_error;
|
||||
pgno_t mc_next_pgno;
|
||||
short mc_toggle; /* Buffer number in provider */
|
||||
short mc_new; /* (0-2 buffers to write) | (MDBX_EOF at end) */
|
||||
/* Error code. Never cleared if set. Both threads can set nonzero
|
||||
* to fail the copy. Not mutex-protected, MDBX expects atomic int. */
|
||||
volatile int mc_error;
|
||||
} mdbx_copy;
|
||||
|
||||
/* Dedicated writer thread for compacting copy. */
|
||||
@ -9168,7 +9168,7 @@ static THREAD_RESULT __cold THREAD_CALL mdbx_env_copythr(void *arg) {
|
||||
* [in] adjust (1 to hand off 1 buffer) | (MDBX_EOF when ending). */
|
||||
static int __cold mdbx_env_cthr_toggle(mdbx_copy *my, int adjust) {
|
||||
mdbx_condmutex_lock(&my->mc_condmutex);
|
||||
my->mc_new += adjust;
|
||||
my->mc_new += (short)adjust;
|
||||
mdbx_condmutex_signal(&my->mc_condmutex);
|
||||
while (my->mc_new & 2) /* both buffers in use */
|
||||
mdbx_condmutex_wait(&my->mc_condmutex);
|
||||
@ -9279,7 +9279,7 @@ static int __cold mdbx_env_cwalk(mdbx_copy *my, pgno_t *pg, int flags) {
|
||||
}
|
||||
|
||||
memcpy(&db, NODEDATA(ni), sizeof(db));
|
||||
my->mc_toggle = toggle;
|
||||
my->mc_toggle = (short)toggle;
|
||||
rc = mdbx_env_cwalk(my, &db.md_root, ni->mn_flags & F_DUPDATA);
|
||||
if (rc)
|
||||
goto done;
|
||||
|
Loading…
Reference in New Issue
Block a user