Added safe lock

Change-Id: I0166ae136d462af1ba7672ffcbbffae2c92285ef
Partially fixes bug: #1373632