private WindowCache(WindowCacheConfig cfg) { tableSize = TableSize(cfg); int lockCount = LockCount(cfg); if (tableSize < 1) { throw new ArgumentException(JGitText.Get().tSizeMustBeGreaterOrEqual1); } if (lockCount < 1) { throw new ArgumentException(JGitText.Get().lockCountMustBeGreaterOrEqual1); } queue = new ReferenceQueue <ByteWindow>(); clock = new AtomicLong(1); table = new AtomicReferenceArray <WindowCache.Entry>(tableSize); locks = new WindowCache.Lock[lockCount]; for (int i = 0; i < locks.Length; i++) { locks[i] = new WindowCache.Lock(); } evictLock = new ReentrantLock(); int eb = (int)(tableSize * .1); if (64 < eb) { eb = 64; } else { if (eb < 4) { eb = 4; } } if (tableSize < eb) { eb = tableSize; } evictBatch = eb; maxFiles = cfg.GetPackedGitOpenFiles(); maxBytes = cfg.GetPackedGitLimit(); mmap = cfg.IsPackedGitMMAP(); windowSizeShift = Bits(cfg.GetPackedGitWindowSize()); windowSize = 1 << windowSizeShift; openFiles = new AtomicInteger(); openBytes = new AtomicLong(); if (maxFiles < 1) { throw new ArgumentException(JGitText.Get().openFilesMustBeAtLeast1); } if (maxBytes < windowSize) { throw new ArgumentException(JGitText.Get().windowSizeMustBeLesserThanLimit); } }
private void CheckLimits(WindowCacheConfig cfg) { WindowCache cache = WindowCache.GetInstance(); NUnit.Framework.Assert.IsTrue(cache.GetOpenFiles() <= cfg.GetPackedGitOpenFiles() ); NUnit.Framework.Assert.IsTrue(cache.GetOpenBytes() <= cfg.GetPackedGitLimit()); NUnit.Framework.Assert.IsTrue(0 < cache.GetOpenFiles()); NUnit.Framework.Assert.IsTrue(0 < cache.GetOpenBytes()); }
private static int TableSize(WindowCacheConfig cfg) { int wsz = cfg.GetPackedGitWindowSize(); long limit = cfg.GetPackedGitLimit(); if (wsz <= 0) { throw new ArgumentException(JGitText.Get().invalidWindowSize); } if (limit < wsz) { throw new ArgumentException(JGitText.Get().windowSizeMustBeLesserThanLimit); } return((int)Math.Min(5 * (limit / wsz) / 2, 2000000000)); }