Replaces __sync_swap with std::atomic

Change-Id: I6cc5eab47d47ab3b85311830e37dfdc5f3ffcbd6