Backport of lock changes.