More packfile locking

We are 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. This also expands the threading tests to put more pressure on the packfile code to hopefully flush out these issues more easily.

(Also fixed some compile warnings in src/index.c)