From b39da2994f12fece2109ecfd10d46b1a715d97df Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 6 Jul 2020 10:34:30 -0400 Subject: [PATCH] Correct total size of Semaphore to be 64 Change-Id: I20db76eab06fc8a0b3869348c537e7303dfa6466 [ROCm/clr commit: dabda131bd2c69ca3114ca6c1670cd750f881a8e] --- projects/clr/rocclr/thread/semaphore.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/projects/clr/rocclr/thread/semaphore.hpp b/projects/clr/rocclr/thread/semaphore.hpp index 9231676ef1..1d725d43cb 100644 --- a/projects/clr/rocclr/thread/semaphore.hpp +++ b/projects/clr/rocclr/thread/semaphore.hpp @@ -46,12 +46,16 @@ class Semaphore : public HeapObject { private: std::atomic_int state_; //!< This semaphore's value. + // The base class size is 1, so padding alignment is needed. + static constexpr size_t state_size = sizeof(std::atomic_int) + + alignof(std::atomic_int); + #ifdef _WIN32 void* handle_; //!< The semaphore object's handle. - char padding_[64 - sizeof(void*) - sizeof(std::atomic_int)]; + char padding_[64 - state_size - sizeof(handle_))]; #else // !_WIN32 sem_t sem_; //!< The semaphore object's identifier. - char padding_[64 - sizeof(sem_t) - sizeof(std::atomic_int)]; + char padding_[64 - state_size - sizeof(sem_)]; #endif /*!_WIN32*/ public: @@ -68,6 +72,9 @@ class Semaphore : public HeapObject { void reset() { state_.store(0, std::memory_order_release); } }; +static_assert(sizeof(Semaphore) == 64 , + "unexpected total size of Semaphore"); + /*! @} * @} */