diff --git a/src/bits.h b/src/bits.h index 76a6b9a8..a46ac42c 100644 --- a/src/bits.h +++ b/src/bits.h @@ -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) diff --git a/src/mdbx.c b/src/mdbx.c index 5b65980c..85378b31 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -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