Generic atomic update code

Couldn't resist doing a little cleanup before writing a test.
Yeah, I wanted to run it through travis commented out (and indeed, it fails). Doesn't this allow for a race between two users setting it for the first time?