Generic atomic update code