Fix race condition in lock upgrade.