Idiomatic Go: use defer for mutex unlocks.

Per Go idioms, this PR shifts mutex unlocks to happen as deferred expressions declared immediately after locking, rather than at the end of the method body.