Simplify and improve atomic primitives

Use GCC's C11-style __atomic builtins where feasible, simplifying the code and removing memory clobbers.  Tighten CAS sequence constraints to avoid memory clobbers.