Exemple #1
0
 /// <summary>Release the current window cursor.</summary>
 /// <remarks>Release the current window cursor.</remarks>
 public override void Release()
 {
     window = null;
     try
     {
         InflaterCache.Release(inf);
     }
     finally
     {
         inf = null;
     }
 }
Exemple #2
0
        /// <summary>Lookup a cached object, creating and loading it if it doesn't exist.</summary>
        /// <remarks>Lookup a cached object, creating and loading it if it doesn't exist.</remarks>
        /// <param name="pack">the pack that "contains" the cached object.</param>
        /// <param name="position">offset within <code>pack</code> of the object.</param>
        /// <returns>the object reference.</returns>
        /// <exception cref="System.IO.IOException">
        /// the object reference was not in the cache and could not be
        /// obtained by
        /// <see cref="Load(PackFile, long)">Load(PackFile, long)</see>
        /// .
        /// </exception>
        private ByteWindow GetOrLoad(PackFile pack, long position)
        {
            int slot = Slot(pack, position);

            WindowCache.Entry e1 = table.Get(slot);
            ByteWindow        v  = Scan(e1, pack, position);

            if (v != null)
            {
                return(v);
            }
            lock (LockCache(pack, position))
            {
                WindowCache.Entry e2 = table.Get(slot);
                if (e2 != e1)
                {
                    v = Scan(e2, pack, position);
                    if (v != null)
                    {
                        return(v);
                    }
                }
                v = Load(pack, position);
                WindowCache.Ref @ref = CreateRef(pack, position, v);
                Hit(@ref);
                for (; ;)
                {
                    WindowCache.Entry n = new WindowCache.Entry(Clean(e2), @ref);
                    if (table.CompareAndSet(slot, e2, n))
                    {
                        break;
                    }
                    e2 = table.Get(slot);
                }
            }
            if (evictLock.TryLock())
            {
                try
                {
                    Gc();
                    Evict();
                }
                finally
                {
                    evictLock.Unlock();
                }
            }
            return(v);
        }
Exemple #3
0
        /// <exception cref="System.IO.IOException"></exception>
        internal void Pin(PackFile pack, long position)
        {
            ByteWindow w = window;

            if (w == null || !w.Contains(pack, position))
            {
                // If memory is low, we may need what is in our window field to
                // be cleaned up by the GC during the get for the next window.
                // So we always clear it, even though we are just going to set
                // it again.
                //
                window = null;
                window = WindowCache.Get(pack, position);
            }
        }
Exemple #4
0
        /// <exception cref="System.IO.IOException"></exception>
        internal static ByteWindow Get(PackFile pack, long offset)
        {
            NGit.Storage.File.WindowCache c = cache;
            ByteWindow r = c.GetOrLoad(pack, c.ToStart(offset));

            if (c != cache)
            {
                // The cache was reconfigured while we were using the old one
                // to load this window. The window is still valid, but our
                // cache may think its still live. Ensure the window is removed
                // from the old cache so resources can be released.
                //
                c.RemoveAll();
            }
            return(r);
        }
Exemple #5
0
 private ByteWindow Scan(WindowCache.Entry n, PackFile pack, long position)
 {
     for (; n != null; n = n.next)
     {
         WindowCache.Ref r = n.@ref;
         if (r.pack == pack && r.position == position)
         {
             ByteWindow v = r.Get();
             if (v != null)
             {
                 Hit(r);
                 return(v);
             }
             n.Kill();
             break;
         }
     }
     return(null);
 }
Exemple #6
0
 private WindowCache.Ref CreateRef(PackFile p, long o, ByteWindow v)
 {
     WindowCache.Ref @ref = new WindowCache.Ref(p, o, v, queue);
     openBytes.AddAndGet(@ref.size);
     return(@ref);
 }
		/// <summary>Release the current window cursor.</summary>
		/// <remarks>Release the current window cursor.</remarks>
		public override void Release()
		{
			window = null;
			try
			{
				InflaterCache.Release(inf);
			}
			finally
			{
				inf = null;
			}
		}
		/// <exception cref="System.IO.IOException"></exception>
		internal void Pin(PackFile pack, long position)
		{
			ByteWindow w = window;
			if (w == null || !w.Contains(pack, position))
			{
				// If memory is low, we may need what is in our window field to
				// be cleaned up by the GC during the get for the next window.
				// So we always clear it, even though we are just going to set
				// it again.
				//
				window = null;
				window = WindowCache.Get(pack, position);
			}
		}