Fix the RecursiveMutex class which would never have worked before.

There are typos and race conditions in the current RecursiveMutex implementation.