Fix RWMutex to be thread-safe when pthread_rwlock is not available