mdbx: fix cache-aligned size for MDBX_reader.

Change-Id: I1e48dd279106daa629fbcd427ec841828799c8f6
This commit is contained in:
Leo Yuriev 2017-05-28 13:48:11 +03:00
parent bb5e1b43af
commit f945e8a062
2 changed files with 9 additions and 6 deletions

View File

@ -225,10 +225,10 @@ typedef struct MDBX_reader {
volatile mdbx_tid_t mr_tid;
/* cache line alignment */
uint8_t pad[~(MDBX_CACHELINE_SIZE - 1) &
(sizeof(txnid_t) + sizeof(mdbx_pid_t) + sizeof(mdbx_tid_t) +
MDBX_CACHELINE_SIZE - 1)];
} MDBX_reader;
uint8_t pad[MDBX_CACHELINE_SIZE -
(sizeof(txnid_t) + sizeof(mdbx_pid_t) + sizeof(mdbx_tid_t)) %
MDBX_CACHELINE_SIZE];
} __cache_aligned MDBX_reader;
/* Information about a single database in the environment. */
typedef struct MDBX_db {
@ -347,12 +347,12 @@ typedef struct MDBX_lockinfo {
/* The number of slots that have been used in the reader table.
* This always records the maximum count, it is not decremented
* when readers release their slots. */
__cache_aligned volatile unsigned mti_numreaders;
volatile unsigned __cache_aligned mti_numreaders;
#ifdef MDBX_OSAL_LOCK
/* Mutex protecting access to this table. */
MDBX_OSAL_LOCK mti_rmutex;
#endif
MDBX_reader mti_readers[1];
MDBX_reader __cache_aligned mti_readers[1];
} MDBX_lockinfo;
#pragma pack(pop)

View File

@ -2208,6 +2208,9 @@ static int mdbx_txn_renew0(MDBX_txn *txn, unsigned flags) {
}
}
STATIC_ASSERT(sizeof(MDBX_reader) == MDBX_CACHELINE_SIZE);
STATIC_ASSERT(
offsetof(MDBX_lockinfo, mti_numreaders) % MDBX_CACHELINE_SIZE == 0);
r = &env->me_lck->mti_readers[i];
/* Claim the reader slot, carefully since other code
* uses the reader table un-mutexed: First reset the