Guaranteed relative finalization order for SafeHandleBase and git_threads_shutdown()

This is a squashed commit resulting from the following work:
https://github.com/libgit2/libgit2sharp/pull/358