add conditional to locking

Signed-off-by: Jens Nyberg <jens.nyberg@gmail.com>