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"); + /*! @} * @} */