[ubsan] Use __sanitizer::atomic_exchange(), prefer shared impl.

Specify weaker memory order in case we optimize for it in the future,
presently still doing same __sync_lock_test_and_set() as before.

Change suggested by Alexey Samsonov, thanks!