Add `mutex_unlock_and_lock()` function

This patch adds the function `mutex_unlock_and_lock()`, which atomically
unlocks one mutex, and locks another.

Remove internal function `mutex_wait()` and further refactor remnants.