Implement do_locked, do_unlocked.

These function will lock or unlock a lockable for the duration of their
argument functions.
Useful for self-documenting code, but also eliminates temporaries on the stack.