Example #1
0
 public void PointToPointPerfTestWithInt(FiberBase fiber)
 {
     using (fiber)
     {
         fiber.Start();
         var       channel = new Channel <int>();
         const int Max     = 5000000;
         var       reset   = new AutoResetEvent(false);
         var       counter = new CounterInt(reset, Max);
         channel.Subscribe(fiber, counter.OnMsg);
         Thread.Sleep(100);
         for (int i = 0; i <= Max; i++)
         {
             channel.Publish(i);
         }
         using (new PerfTimer(Max))
         {
             for (int i = 0; i <= Max; i++)
             {
                 channel.Publish(i);
             }
             Assert.IsTrue(reset.WaitOne(30000, false));
         }
     }
 }
Example #2
0
 public void PointToPointPerfTestWithObject(FiberBase fiber)
 {
     using (fiber)
     {
         fiber.Start();
         var             channel = new Channel <object>();
         const int       max     = 5000000;
         var             reset   = new AutoResetEvent(false);
         var             end     = new object();
         Action <object> onMsg   = delegate(object msg)
         {
             if (msg == end)
             {
                 reset.Set();
             }
         };
         channel.Subscribe(fiber, onMsg);
         Thread.Sleep(100);
         using (new PerfTimer(max))
         {
             var msg = new object();
             for (int i = 0; i <= max; i++)
             {
                 channel.Publish(msg);
             }
             channel.Publish(end);
             Assert.IsTrue(reset.WaitOne(30000, false));
         }
     }
 }
Example #3
0
 public void PointToPointPerfTestWithObject(FiberBase fiber)
 {
     using (fiber)
     {
         fiber.Start();
         var channel = new Channel<object>();
         const int max = 5000000;
         var reset = new AutoResetEvent(false);
         var end = new object();
         Action<object> onMsg = delegate(object msg)
         {
             if (msg == end)
                 reset.Set();
         };
         channel.Subscribe(fiber, onMsg);
         Thread.Sleep(100);
         using (new PerfTimer(max))
         {
             var msg = new object();
             for (int i = 0; i <= max; i++)
                 channel.Publish(msg);
             channel.Publish(end);
             Assert.IsTrue(reset.WaitOne(30000, false));
         }
     }
 }
Example #4
0
 public Enumerator(Action <Func <T, bool> > enumProc, IFiberFactory fiberFactory)
 {
     this.fiberFactory = fiberFactory;
     enumFiber         = fiberFactory.CreateNew(
         () => {
         enumProc(FiberNext);
         state = -1;
         mainFiber.Switch();
     }
         );
 }
Example #5
0
 public void Dispose()
 {
     if (state == 0)
     {
         state = -1;
         enumFiber.Dispose();
     }
     else if (state != -1)
     {
         state     = -1;
         mainFiber = fiberFactory.CurrentFiber;
         try{
             enumFiber.Switch();
         }finally{
             mainFiber = null;
         }
         enumFiber.Dispose();
     }
 }
Example #6
0
 public void PointToPointPerfTestWithInt(FiberBase fiber)
 {
     using (fiber)
     {
         fiber.Start();
         var channel = new Channel<int>();
         const int max = 5000000;
         var reset = new AutoResetEvent(false);
         var counter = new CounterInt(reset, max);
         channel.Subscribe(fiber, counter.OnMsg);
         Thread.Sleep(100);
         using (new PerfTimer(max))
         {
             for (int i = 0; i <= max; i++)
                 channel.Publish(i);
             Assert.IsTrue(reset.WaitOne(30000, false));
         }
     }
 }
Example #7
0
            public bool MoveNext()
            {
                if (state == 0 || state == 1)
                {
                    mainFiber = fiberFactory.CurrentFiber;
                    try{
                        enumFiber.Switch();
                    }finally{
                        mainFiber = null;
                    }

                    if (state == 1)
                    {
                        return(true);
                    }
                    enumFiber.Dispose();
                    return(false);
                }
                return(false);
            }
Example #8
0
 private static void PointToPointPerfTestWithStruct(FiberBase fiber)
 {
     using (fiber)
     {
         fiber.Start();
         IChannel <MsgStruct> channel = new Channel <MsgStruct>();
         const int            max     = 5000000;
         var reset   = new AutoResetEvent(false);
         var counter = new Counter(reset, max);
         channel.Subscribe(fiber, counter.OnMsg);
         Thread.Sleep(100);
         using (new PerfTimer(max))
         {
             for (int i = 0; i <= max; i++)
             {
                 channel.Publish(new MsgStruct {
                     count = i
                 });
             }
             Assert.IsTrue(reset.WaitOne(30000, false));
         }
     }
 }