Classes | |
struct | pw::NaturallyAligned< T > |
Typedefs | |
template<typename T > | |
using | pw::AlignedAtomic = std::atomic< NaturallyAligned< T > > |
using pw::AlignedAtomic = typedef std::atomic<NaturallyAligned<T> > |
Ensures the object held by std::atomic
is naturally aligned. This enables the compiler to replace libcalls to atomic functions with native instructions when appropriate. AlignedAtomic
is a convenience wrapper.
Example:
std::optional<bool>
has a size of 2 but alignment of 1, which would normally lower to an __atomic_*
libcall, but pw::NaturallyAligned
in std::atomic
tells the compiler to align the object to 2 bytes, which satisfies the requirements for replacing __atomic_*
with native instructions.