Add condition variables function wrappers to handle unexpected failure.
For consistency, rename lock_mutex and unlock_mutex to mutex_lock and mutex_unlock.
Start a new clean history from here.