Exemple #1
0
        private static void OnProxyDisposed(CacheItemProxy cacheItemProxy)
        {
            ReferenceCountedObjectWrapper <CacheItem> wrapper = cacheItemProxy.Wrapper;

            if (!wrapper.IsReferenceCountAboveZero())
            {
                lock (_syncLock)
                {
                    //The count could have gone back up
                    if (wrapper.IsReferenceCountAboveZero())
                    {
                        return;
                    }

                    CacheItem cacheItem = wrapper.Item;
                    _cache.Remove(cacheItem.Key);
                    cacheItem.Dispose();

                    if (_cache.Count == 0)
                    {
                        Trace.WriteLine("The composed lut cache is empty.", "LUT");
                    }
                }
            }
        }
            public void Dispose()
            {
                try
                {
                    if (_wrapper == null)
                    {
                        return;
                    }

                    _wrapper.DecrementReferenceCount();
                    if (_wrapper.IsReferenceCountAboveZero())
                    {
                        return;
                    }

                    _proxy = null;

                    _wrapper.Item.Dispose();
                    _wrapper = null;

                    GC.SuppressFinalize(this);
                }
                catch (Exception e)
                {
                    Platform.Log(LogLevel.Error, e);
                }
            }
Exemple #3
0
            public void Dispose()
            {
                try
                {
                    if (_wrapper == null)
                    {
                        return;
                    }

                    _wrapper.DecrementReferenceCount();
                    OnProxyDisposed(this);
                    _wrapper   = null;
                    _cacheItem = null;

                    GC.SuppressFinalize(this);
                }
                catch (Exception e)
                {
                    Platform.Log(LogLevel.Debug, e);
                }
            }
Exemple #4
0
        private static CacheItemProxy CreateItemProxy(IEnumerable <IComposableLut> luts)
        {
            string key = GetKey(luts);

            lock (_syncLock)
            {
                CleanupDeadItems();

                ReferenceCountedObjectWrapper <CacheItem> wrapper;
                if (!_cache.ContainsKey(key))
                {
                    wrapper     = new ReferenceCountedObjectWrapper <CacheItem>(new CacheItem(key));
                    _cache[key] = new WeakReference(wrapper);
                }
                else
                {
                    WeakReference reference = _cache[key];
                    try
                    {
                        wrapper = reference.Target as ReferenceCountedObjectWrapper <CacheItem>;
                    }
                    catch (InvalidOperationException)
                    {
                        wrapper = null;
                    }

                    if (wrapper == null)
                    {
                        wrapper     = new ReferenceCountedObjectWrapper <CacheItem>(new CacheItem(key));
                        _cache[key] = new WeakReference(wrapper);
                    }
                }

                return(new CacheItemProxy(wrapper));
            }
        }
Exemple #5
0
 internal CacheItemProxy(ReferenceCountedObjectWrapper <CacheItem> wrapper)
 {
     _wrapper   = wrapper;
     _cacheItem = _wrapper.Item;
     _wrapper.IncrementReferenceCount();
 }
 public RendererProxy(RendererBase realRenderer)
 {
     _wrapper = new ReferenceCountedObjectWrapper <RendererBase>(realRenderer);
 }