コード例 #1
0
ファイル: WindowCache.cs プロジェクト: TetradogOther/NGit
 /// <summary>Clear all entries related to a single file.</summary>
 /// <remarks>
 /// Clear all entries related to a single file.
 /// <p>
 /// Typically this method is invoked during
 /// <see cref="PackFile.Close()">PackFile.Close()</see>
 /// , when we
 /// know the pack is never going to be useful to us again (for example, it no
 /// longer exists on disk). A concurrent reader loading an entry from this
 /// same pack may cause the pack to become stuck in the cache anyway.
 /// </remarks>
 /// <param name="pack">the file to purge all entries of.</param>
 private void RemoveAll(PackFile pack)
 {
     for (int s = 0; s < tableSize; s++)
     {
         WindowCache.Entry e1 = table.Get(s);
         bool hasDead         = false;
         for (WindowCache.Entry e = e1; e != null; e = e.next)
         {
             if ([email protected] == pack)
             {
                 e.Kill();
                 hasDead = true;
             }
             else
             {
                 if (e.dead)
                 {
                     hasDead = true;
                 }
             }
         }
         if (hasDead)
         {
             table.CompareAndSet(s, e1, Clean(e1));
         }
     }
     Gc();
 }
コード例 #2
0
ファイル: WindowCache.cs プロジェクト: TetradogOther/NGit
 private void Evict()
 {
     while (IsFull())
     {
         int ptr = rng.Next(tableSize);
         WindowCache.Entry old = null;
         int slot = 0;
         for (int b = evictBatch - 1; b >= 0; b--, ptr++)
         {
             if (tableSize <= ptr)
             {
                 ptr = 0;
             }
             for (WindowCache.Entry e = table.Get(ptr); e != null; e = e.next)
             {
                 if (e.dead)
                 {
                     continue;
                 }
                 if (old == null || [email protected] < [email protected])
                 {
                     old  = e;
                     slot = ptr;
                 }
             }
         }
         if (old != null)
         {
             old.Kill();
             Gc();
             WindowCache.Entry e1 = table.Get(slot);
             table.CompareAndSet(slot, e1, Clean(e1));
         }
     }
 }
コード例 #3
0
ファイル: WindowCache.cs プロジェクト: TetradogOther/NGit
 /// <summary>Clear every entry from the cache.</summary>
 /// <remarks>
 /// Clear every entry from the cache.
 /// <p>
 /// This is a last-ditch effort to clear out the cache, such as before it
 /// gets replaced by another cache that is configured differently. This
 /// method tries to force every cached entry through
 /// <see cref="Clear(Ref)">Clear(Ref)</see>
 /// to
 /// ensure that resources are correctly accounted for and cleaned up by the
 /// subclass. A concurrent reader loading entries while this method is
 /// running may cause resource accounting failures.
 /// </remarks>
 private void RemoveAll()
 {
     for (int s = 0; s < tableSize; s++)
     {
         WindowCache.Entry e1;
         do
         {
             e1 = table.Get(s);
             for (WindowCache.Entry e = e1; e != null; e = e.next)
             {
                 e.Kill();
             }
         }while (!table.CompareAndSet(s, e1, null));
     }
     Gc();
 }
コード例 #4
0
ファイル: WindowCache.cs プロジェクト: TetradogOther/NGit
 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);
 }