Pigweed
 
Loading...
Searching...
No Matches
Pw_alignment

Classes

struct  pw::NaturallyAligned< T >
 

Typedefs

template<typename T >
using pw::AlignedAtomic = std::atomic< NaturallyAligned< T > >
 

Detailed Description

Typedef Documentation

◆ AlignedAtomic

template<typename 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:

#include "pw_alignment/alignment.h"
std::atomic< NaturallyAligned< T > > AlignedAtomic
Definition: alignment.h:105

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.