Replace racy half-open increment-if-zero with a compare-and-swap