Simplify code for checking lock

Signed-off-by: Michal Čihař <michal@cihar.com>
Move out own lock detection

Signed-off-by: Michal Čihař <michal@cihar.com>
Simplify lock detection

Signed-off-by: Michal Čihař <michal@cihar.com>