Added safe relock function 

Required a changed in the lock function to return the lock ID instead of the unlock callback.
Perhaps rather than changing the unlock function result, we can either set the lock ID as a property on the unlock function, or add it as another parameter to the lock callback. That way the API change is additive rather than breaking.