Exemplo n.º 1
0
        private static void ReadThreadFunc(object state)
        {
            int count = 0;

            while (value < Result && count < CheckCount)
            {
                int element;
                while (ypipe.Read(out element))
                {
                    Atomic.Add(ref value, element);
                }
                Soyo.Base.Thread.Sleep(1);
                count++;
            }
        }
Exemplo n.º 2
0
        public void TestApi()
        {
            ypipe = new CachePipe <int>();

            int valueResult;

            valueResult = ypipe.Peek();
            Assert.AreEqual(valueResult, default(int));

            int value = 1;
            var rc    = ypipe.Write(ref value);

            Assert.IsTrue(rc);
            Assert.AreEqual(ypipe.Count, 1);

            valueResult = ypipe.Peek();
            Assert.AreEqual(valueResult, value);

            rc = ypipe.CheckRead();
            Assert.IsTrue(rc);

            rc = ypipe.Unwrite(out valueResult);
            Assert.IsFalse(rc);
            Assert.AreEqual(valueResult, default(int));

            rc = ypipe.Read(out valueResult);
            Assert.IsTrue(rc);
            Assert.AreEqual(valueResult, value);

            rc = ypipe.CheckRead();
            Assert.IsFalse(rc);

            rc = ypipe.Read(out valueResult);
            Assert.IsFalse(rc);
            Assert.AreEqual(valueResult, default(int));

            ypipe.WriteBegin(ref value);
            rc = ypipe.CheckRead();
            Assert.IsFalse(rc);
            rc = ypipe.Read(out valueResult);
            Assert.IsFalse(rc);

            rc = ypipe.Write(ref value);
            Assert.IsFalse(rc);
            rc = ypipe.CheckRead();
            Assert.IsFalse(rc);
            rc = ypipe.Read(out valueResult);
            Assert.IsFalse(rc);

            rc = ypipe.Unwrite(out valueResult);
            Assert.IsTrue(rc);
            Assert.AreEqual(valueResult, value);

            rc = ypipe.WriteEnd(ref value);
            Assert.IsTrue(rc);
            rc = ypipe.CheckRead();
            Assert.IsTrue(rc);

            rc = ypipe.Unwrite(out valueResult);
            Assert.IsFalse(rc);
            Assert.AreEqual(valueResult, default(int));

            ypipe.Clear();
            Assert.AreEqual(ypipe.Count, 0);

            rc = ypipe.Write(ref value);
            Assert.IsTrue(rc);
            rc = ypipe.Write(ref value);
            Assert.IsTrue(rc);

            var array = ypipe.ReadAll();

            Assert.AreEqual(array.Length, 2);
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(array[i], value);
            }

            Assert.AreEqual(ypipe.Count, 0);
        }