Esempio n. 1
0
        public async Task Test_Queue_Performance(IMpScQueue <IWorkItem> queueWorkItem)
        {
            _TestOutputHelper.WriteLine(queueWorkItem.GetType().Name);

            var       fiber = GetSafeFiber(queueWorkItem);
            var       reset = new AutoResetEvent(false);
            const int max   = 5000000;

            Action <int> @do = (count) =>
            {
                if (count == max)
                {
                    reset.Set();
                }
            };

            using (GetPerfTimer(max))
            {
                for (var i = 0; i <= max; i++)
                {
                    var i1 = i;
                    fiber.Dispatch(() => @do(i1));
                }
                reset.WaitOne(30000, false).Should().BeTrue();
            }

            await fiber.DisposeAsync();
        }
Esempio n. 2
0
        public async Task Test_Queue_Performance(IMpScQueue <IWorkItem> queueWorkItem)
        {
            Output(queueWorkItem.GetType().Name);

            var fiber   = new MonoThreadedFiber(null, queueWorkItem);
            var factory = _FactoryBuilder.GetFactoryForFiber(fiber);

            await TestNoTask(factory);

            await fiber.DisposeAsync();
        }
Esempio n. 3
0
        public MonoThreadedFiber(Action <Thread> onCreate = null, IMpScQueue <IWorkItem> queue = null)
        {
            _TaskQueue = queue ?? new BlockingMpscQueue <IWorkItem>();
            _Current   = new Thread(Consume)
            {
                IsBackground = true,
                Name         = $"MonoThreadedQueue-{_Count++}"
            };

            onCreate?.Invoke(_Current);
            _Current.Start();
        }
Esempio n. 4
0
        protected IMonoThreadFiber GetSafeFiber(IMpScQueue <IWorkItem> queue)
        {
            var fiber = GetFiber(queue);

            return(_Disposables.Add(fiber));
        }
Esempio n. 5
0
 protected abstract IMonoThreadFiber GetFiber(IMpScQueue <IWorkItem> queue);
 protected override IMonoThreadFiber GetFiber(IMpScQueue <IWorkItem> queue) => new MonoThreadedFiber(null, queue);
 protected override IMonoThreadFiber GetFiber(IMpScQueue <IWorkItem> queue) => new ThreadPoolFiber(queue);
Esempio n. 8
0
 public ThreadPoolFiber(IMpScQueue <IWorkItem> queue = null)
 {
     _TaskQueue = queue ?? new BlockingMpscQueue <IWorkItem>();
     ThreadPool.QueueUserWorkItem(_ => Consume());
 }