neat piece of invisible infrastructure: the Rust portable-atomic crate
your platform doesnโt support a particular type of atomic natively? not a problem, this crate gives you an implementation anyway
how? well thereโs a global lock, you see. or, rather, 67 global locks, and which one gets used depends on the address of the atomic mod 67.
but, thatโs kinda inefficient, so you wouldnโt want to use it unless itโs your only choice, right?
so they have a bunch of platform specific implementations, such as โletโs detect at runtime if cmpxchg16b is supportedโ or โthis is a microcontroller so if we read it within one instruction weโre fine, and otherwise just disable the interruptsโ
and as a result you can just use it and not really think about it, because in 99% of cases itโs gonna do the same thing as what youโd end up with if you bothered to optimize it manually
the ratio of elaborate internals to unassuming API surface is so great here you could easily blink and miss the fact that someone is pulling off heroic feats to make this happen