Locks are counted. If you locked surface twice, you have to unlock it twice. Better avoid this scheme - the same function that locked surface should unlock it after its job is done.
You can look at surface->locked
variable, which is locks count, but it isn't included in documentation so you can't rely on this name - it could be changed in future versions.