Use proper locking function (via the generic locking API)
Reported by Max E. Reyes Vera Juarez.