Implement reentrant mutexes.

We can't rely on libuv ones to be reentrant, so we need to build the
recursion support ourselves.