private void Do(int C, int P, int M, bool noisy, bool useRAII, Func <Queue <int>, int> test) { var pool = QueuePool <int> .Create(C); void testCore(Queue <int> queue) { var len = queue.Count; Assert.AreEqual(0, len); var L = test(queue); len = queue.Count; Assert.AreEqual(L, len); } if (useRAII) { Run(() => pool.New(), o => o.Queue, o => o.Dispose(), testCore, P, M, noisy); } else { Run(() => pool.Allocate(), o => o, o => pool.Free(o), testCore, P, M, noisy); } }
public void PooledQueue_GottenTooBig() { var bigPool = QueuePool <int> .Create(1, 16, 2048); var smallPool = QueuePool <int> .Create(1, 16, 16); TooBig(() => PooledQueue <int> .New(), h => h.Queue, (h, n) => { for (var i = 0; i < n; i++) { h.Enqueue(i); } }, 1024); TooBig(() => bigPool.New(), h => h.Queue, (h, n) => { for (var i = 0; i < n; i++) { h.Enqueue(i); } }, 2048); TooBig(() => smallPool.New(), h => h.Queue, (h, n) => { for (var i = 0; i < n; i++) { h.Enqueue(i); } }, 16); }
public FastQueueImpl(object name, int maxSize) { instanceLog = Factory.SysLog.GetLogger("TickZoom.TickUtil.FastQueue." + name); if (debug) { log.Debug("Created with capacity " + maxSize); } if (name is string) { this.name = (string)name; } else if (name is Type) { this.name = ((Type)name).Name; } this.maxSize = maxSize; this.lowWaterMark = maxSize / 2; this.highWaterMark = maxSize / 2; queue = QueuePool.Create(); queue.Clear(); lock ( locker) { queueList.Add(this); } }
public void PooledQueue_ArgumentChecking() { Assert.ThrowsException <ArgumentOutOfRangeException>(() => QueuePool <int> .Create(4, -1)); Assert.ThrowsException <ArgumentOutOfRangeException>(() => QueuePool <int> .Create(4, 16, -1)); }
public void PooledQueue_Simple2() { var pool = QueuePool <string> .Create(4, 16); PooledQueue_Simple_Impl(pool); }