data-sort: replace grace period hack with propper locking.

Now instead of double-check-locking we use refcounting to guard writes
inside critical section.