From 3ae9c5309bee6fa3a68ba8934664adcf885f12fa Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Tue, 5 Apr 2022 18:32:05 -0700 Subject: [PATCH] Remove explicit padding from CacheAlignedInstrumentedMutex (#9809) Summary: Fixes https://github.com/facebook/rocksdb/issues/9779. The padding at the end of a struct is added implicitly according to the sizeof spec: "When applied to a class, the result is the number of bytes in an object of that class including any padding required for placing objects of that type in an array" (https://eel.is/c++draft/expr.sizeof#2.sentence-2). We should drop the explicit padding since it assumed support for zero-length arrays, which is non-standard. Pull Request resolved: https://github.com/facebook/rocksdb/pull/9809 Test Plan: rely on CI Reviewed By: riversand963 Differential Revision: D35413496 Pulled By: ajkr fbshipit-source-id: 25d52ca45e648ad0d5657149f26f6adecbed1cb4 --- monitoring/instrumented_mutex.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/monitoring/instrumented_mutex.h b/monitoring/instrumented_mutex.h index e05c6addd..ea29bb452 100644 --- a/monitoring/instrumented_mutex.h +++ b/monitoring/instrumented_mutex.h @@ -54,10 +54,9 @@ class InstrumentedMutex { class ALIGN_AS(CACHE_LINE_SIZE) CacheAlignedInstrumentedMutex : public InstrumentedMutex { using InstrumentedMutex::InstrumentedMutex; - char padding[(CACHE_LINE_SIZE - sizeof(InstrumentedMutex) % CACHE_LINE_SIZE) % - CACHE_LINE_SIZE] ROCKSDB_FIELD_UNUSED; }; -static_assert(sizeof(CacheAlignedInstrumentedMutex) % CACHE_LINE_SIZE == 0); +static_assert(alignof(CacheAlignedInstrumentedMutex) != CACHE_LINE_SIZE || + sizeof(CacheAlignedInstrumentedMutex) % CACHE_LINE_SIZE == 0); // RAII wrapper for InstrumentedMutex class InstrumentedMutexLock {