Use thread-local storage for the global file_rep_t object.

File replacement and patching should now be sufficiently thread-safe. Hooray.