private static void PopFrontThreadFunc(object state) { int count = 0; while (value < Result && count < CheckCount) { int element; while (yqueue.PopFront(out element)) { Atomic.Add(ref value, element); } Soyo.Base.Thread.Sleep(1); count++; } }
public void TestApi() { yqueue = new CacheQueue <int>(); Assert.AreEqual(yqueue.FrontPos, 0); Assert.AreEqual(yqueue.BackPos, 0); Assert.AreEqual(yqueue.EndPos, 0); int valueResult; valueResult = yqueue.Front; Assert.AreEqual(valueResult, default(int)); valueResult = yqueue.Back; Assert.AreEqual(valueResult, default(int)); var rc = yqueue.PopFront(out valueResult); Assert.IsFalse(rc); rc = yqueue.PopBack(out valueResult); Assert.IsFalse(rc); int value = 1; yqueue.PushBack(ref value); Assert.AreEqual(yqueue.Count, 1); Assert.AreEqual(yqueue.FrontPos, 0); Assert.AreEqual(yqueue.BackPos, 0); Assert.AreEqual(yqueue.EndPos, 1); valueResult = yqueue.Front; Assert.AreEqual(valueResult, value); valueResult = yqueue.Back; Assert.AreEqual(valueResult, value); rc = yqueue.PopFront(out valueResult); Assert.IsTrue(rc); Assert.AreEqual(valueResult, value); Assert.AreEqual(yqueue.Count, 0); Assert.AreEqual(yqueue.FrontPos, 1); Assert.AreEqual(yqueue.BackPos, 0); Assert.AreEqual(yqueue.EndPos, 1); rc = yqueue.PopBack(out valueResult); Assert.IsFalse(rc); Assert.AreEqual(yqueue.Count, 0); Assert.AreEqual(yqueue.FrontPos, 1); Assert.AreEqual(yqueue.BackPos, 0); Assert.AreEqual(yqueue.EndPos, 1); yqueue.PushBack(ref value); Assert.AreEqual(yqueue.Count, 1); Assert.AreEqual(yqueue.FrontPos, 1); Assert.AreEqual(yqueue.BackPos, 1); Assert.AreEqual(yqueue.EndPos, 2); rc = yqueue.PopBack(out valueResult); Assert.IsTrue(rc); Assert.AreEqual(valueResult, value); Assert.AreEqual(yqueue.Count, 0); Assert.AreEqual(yqueue.FrontPos, 1); Assert.AreEqual(yqueue.BackPos, 0); Assert.AreEqual(yqueue.EndPos, 1); rc = yqueue.PopFront(out valueResult); Assert.IsFalse(rc); Assert.AreEqual(yqueue.FrontPos, 1); Assert.AreEqual(yqueue.BackPos, 0); Assert.AreEqual(yqueue.EndPos, 1); yqueue.PushBack(ref value); Assert.AreEqual(yqueue.Count, 1); Assert.AreEqual(yqueue.FrontPos, 1); Assert.AreEqual(yqueue.BackPos, 1); Assert.AreEqual(yqueue.EndPos, 2); yqueue.PushBack(ref value); Assert.AreEqual(yqueue.Count, 2); Assert.AreEqual(yqueue.FrontPos, 1); Assert.AreEqual(yqueue.BackPos, 2); Assert.AreEqual(yqueue.EndPos, 3); var array = yqueue.PopAll(); Assert.AreEqual(array.Length, 2); for (int i = 0; i < array.Length; i++) { Assert.AreEqual(array[i], value); } Assert.AreEqual(yqueue.Count, 0); Assert.AreEqual(yqueue.FrontPos, 3); Assert.AreEqual(yqueue.BackPos, 2); Assert.AreEqual(yqueue.EndPos, 3); yqueue.PushBack(ref value); Assert.AreEqual(yqueue.Count, 1); Assert.AreEqual(yqueue.FrontPos, 3); Assert.AreEqual(yqueue.BackPos, 3); Assert.AreEqual(yqueue.EndPos, 4); yqueue.PushBack(ref value); Assert.AreEqual(yqueue.Count, 2); Assert.AreEqual(yqueue.FrontPos, 3); Assert.AreEqual(yqueue.BackPos, 4); Assert.AreEqual(yqueue.EndPos, 5); yqueue.Clear(); Assert.AreEqual(yqueue.Count, 0); Assert.AreEqual(yqueue.FrontPos, 5); Assert.AreEqual(yqueue.BackPos, 4); Assert.AreEqual(yqueue.EndPos, 5); }