Reverse lock order

helgrind found that the locks were taken in reverse order in some
places. This makes the ordering of locks consistent.
Revert "Reverse lock order"

This reverts commit a7ad186e0f2b643c4e2bf302bc18e892d499cd4a.