Пример #1
0
 internal ThreadPool(ThreadPoolConfig config)
 {
     config.Validate();
     SetThreadingRange(config);
     Name = config.Name;
     MultiThreadingCapacity = config.MultiThreadingCapacity;
     _taskQueueController = config.TaskQueueController;
 }
Пример #2
0
        /// <summary>
        ///     Creates new instance of the <see cref="ITinyThreadPool" />.
        /// </summary>
        /// <param name="config">The configuration.</param>
        /// <returns>New instance of the <see cref="ITinyThreadPool" />.</returns>
        public static ITinyThreadPool Create(Action<IThreadPoolConfig> config)
        {
            var threadPoolConfig = new ThreadPoolConfig();
            config(threadPoolConfig);

            var threadPool = new ThreadPool(threadPoolConfig);
            threadPool.Start();
            return threadPool;
        }
Пример #3
0
 private void SetThreadingRange(ThreadPoolConfig config)
 {
     switch (config.MultiThreadingCapacity)
     {
         case MultiThreadingCapacity.Global:
             MinThreads = config.MinThreads;
             MaxThreads = config.MaxThreads;
             break;
         case MultiThreadingCapacity.PerProcessor:
             int processorCount = Environment.ProcessorCount;
             MinThreads = processorCount * config.MinThreads;
             MaxThreads = processorCount * config.MaxThreads;
             break;
         default:
             string error = string.Format(
                 "Invalid MultiThreadingCapacity: {0}", config.MultiThreadingCapacity);
             throw new ArgumentOutOfRangeException(error);
     }
 }