Improve template constraints for lock().