Add git__compare_and_swap and use it

This removes the lock from the repository object and changes the
internals to use the new atomic git__compare_and_swap to update
the _odb, _config, _index, and _refdb variables in a threadsafe
manner.
Fixes for Windows cas/threading stuff