[PATCH 1/3] Use cache for base repo if possible

Vratislav Podzimek vpodzime at redhat.com
Tue Oct 22 07:16:04 UTC 2013


On Mon, 2013-10-21 at 12:11 -0700, Brian C. Lane wrote:
> On Wed, Oct 16, 2013 at 03:26:21PM +0200, Vratislav Podzimek wrote:
> 
> > -                    base_repo_name = repo_name
> > +                    with self._br_cache_valid_lock:
> > +                        # cache the value for multiple use
> > +                        self._cached_base_repo = repo_name
> > +                        self._br_cache_valid = True
> > +                        current_cached = self._cached_base_repo
> >                      break
> > -
> > -        return base_repo_name
> > +            else:
> > +                # didn't find any base repo set and enabled
> > +                with self._br_cache_valid_lock:
> > +                    # set the cache to None, but make it valid
> > +                    self._cached_base_repo = None
> > +                    self._br_cache_valid = True
> > +                    current_cached = self._cached_base_repo
> > +
> > +        with self._br_refresh_lock:
> > +            # go through scheduled callbacks (if any) and remove them
> > +            for callback in self._br_callbacks:
> > +                callback(current_cached)
> > +                self._br_callbacks.remove(callback)
> 
> Why not just use self._cached_base_repo? I don't see any reason to
> assign it to current_cached.
That's because the I want to get the value while having the lock and
then release it. In case there is some other thread racing with the
current one, callbacks will be called with the value the current thread
has determined even if some other thread messes it up in the meantime.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list