Introduce atomic primitives to refpointer.

The primitives are not lock-free.