Touch up the mutex implementation

This fixes a few bugs, adds some comments, reformats code, and gets it working
with AtomicU64.