xbps: merge patch from master to fix races with multiple threads.

Crash easily triggerable with xbps-query -Ro with 8 threads.

Thanks to @chneukirchen.