local function is_locked_by_another_owner (key, lock_id) local existing_lock = get_existing_lock(key) -- Currently no locks on given key if not existing_lock then return false end -- The caller already owns the lock for the given key if existing_lock == lock_id then return false end debugLog("key '%s' is locked but lock ID does not match (expected='%s', actual='%s')", key, lock_id, existing_lock) return true end local function is_any_locked_by_another_owner (keys, lock_id) for _, key in ipairs(keys) do if is_locked_by_another_owner(key, lock_id) then return true end end return false end local function owns_lock (key, lock_id) local existing_lock = get_existing_lock(key) if existing_lock == lock_id then return true end if existing_lock then debugLog("key '%s' is not locked by lock with ID '%s'. It is currently locked by lock with ID '%s'", key, lock_id, existing_lock) end return false end local function owns_locks (keys, lock_id) for _, key in ipairs(keys) do if not owns_lock(key, lock_id) then return false end end return true end