fix a data race caused by std::atomic usage

There was a window between grabbing the atomically-stored
pointer and unsetting it. The exchange method allows for doing
this in a really atomic fashion, however.

Signed-off-by: Stanislaw Halik <sthalik@misaki.pl>