Simplified mutex-related code in Windows shutdown routine

This changeset applies @ochameau's suggestions from #740. I didn't create a separate boolean variable because I thought the code would be simpler without it, but let me know if I should add that in.