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)); } } }
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)); } } }
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)); } } }
public Enumerator(Action <Func <T, bool> > enumProc, IFiberFactory fiberFactory) { this.fiberFactory = fiberFactory; enumFiber = fiberFactory.CreateNew( () => { enumProc(FiberNext); state = -1; mainFiber.Switch(); } ); }
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(); } }
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)); } } }
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); }
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)); } } }