Add extra locking around packfile open

We were still seeing a few issues in threaded access to packs.
This adds extra locks around the opening of the mwindow to
avoid a different race.
Extra threading tests

We need to hammer the packfile open phase harder in the thread
tests, in addition to the cache API.
Fix some compile warnings and trailing whitespace
Protect sha1_entry_pos call with mutex

There is an occasional assertion failure in sha1_entry_pos from
pack_entry_find_index when running threaded.  Holding the mutex
around the code that grabs the index_map data and processes it
makes this assertion failure go away.
Merge pull request #1529 from arrbee/more-packfile-locking

More packfile locking