Fix a bug with recursive mutex.

The error was a bit weird, since the original code doesn't validate the lock.
The buggy behavior was, at some point, the pthread_mutex_lock simply stall, leading to a dead_lock.

Correctly locking the mutex only once when necessary, matching the number of unlock, just fix that.