Eliminate unnecessary internal locking in mutex.c and clean up logic