Make refcounting atomic

Putting the `objects::cache` test through `drd`'s threading tests shows that you can end up with a wrong refcount if two threads want to allocate an odb for themselves. The same would happen for the index, config.

There still seems to be some issues inside the pack code, but this is a quick fix that gets us closer.

//cc @arrbee