public static TaskPool CreateScavengingTaskPool(Action toRun, TaskPoolOptions options)
        {
            MethodContract.NotNull(toRun, nameof(toRun));
            ScavengingTaskPoolRunner runner = new ScavengingTaskPoolRunner(toRun);
            TaskPool pool = new TaskPool(runner.Run, options);

            runner.pool = pool;
            return(pool);
        }
Exemple #2
0
        private void Setup(Func <T> listener, Action <T> handler, ServerTaskPoolOptions options)
        {
            TaskPoolOptions poolOpts = new TaskPoolOptions();

            poolOpts.MaxActiveWorkers   = options.MaxActiveWorkers;
            poolOpts.MaxWaitingRequests = options.MaxWaitingAccepts;
            poolOpts.Timeout            = options.Timeout;
            this.runner = new ServerRunner <T>(listener, handler, options.MaxWaitingRequests);
            this.pool   = ScavengingTaskPoolRunner.CreateScavengingTaskPool(runner.Run, poolOpts);
        }
Exemple #3
0
        private volatile int activeWaiters = 0; //how many calls to Next() are waiting

        public TaskPool(Action toRun, TaskPoolOptions options)
        {
            MethodContract.NotNull(toRun, nameof(toRun));
            this.options = new TaskPoolOptions();
            if (options != null)
            {
                this.options.MaxWaitingRequests = options.MaxWaitingRequests;
                this.options.MaxActiveWorkers   = options.MaxActiveWorkers;
                this.options.Timeout            = options.Timeout;
            }
            this.activeWorkers = 0;
            this.runner        = new TaskPoolRunner(this, toRun, this.options.Timeout);
            this.Reset();
        }
Exemple #4
0
        private void Setup(Func <T> listener, Action <T> handler, ServerTaskPoolOptions options)
        {
            TaskPoolOptions poolOpts = new TaskPoolOptions();

            poolOpts.MaxActiveWorkers   = options.MaxActiveListenerWorkers;
            poolOpts.MaxWaitingRequests = options.MaxWaitingAccepts;
            poolOpts.Timeout            = options.Timeout;

            this.eventer      = new HandoffEvent <T>(listener, handler, options.MaxWaitingRequests);
            this.handle       = eventer.Handle;
            this.listenerPool = ScavengingTaskPoolRunner.CreateScavengingTaskPool(eventer.Listen, poolOpts);

            this.handlerThreads         = options.MaxActiveHandlerWorkers;
            poolOpts                    = new TaskPoolOptions();
            poolOpts.MaxActiveWorkers   = this.handlerThreads;
            poolOpts.MaxWaitingRequests = options.MaxWaitingRequests;
            poolOpts.Timeout            = new Timeout(0);
            this.handlerPool            = new TaskPool(this.Forever, poolOpts);
        }