コード例 #1
0
        /// <summary>
        /// <see cref="StaticThreadPool"/> constructor
        /// </summary>
        /// <param name="initialThreadCount">Initial number of threads in ThreadPool</param>
        /// <param name="queueBoundedCapacity">The bounded size of the work items queue (if less or equal to 0 then no limitation)</param>
        /// <param name="name">The name for this instance of ThreadPool and for its threads</param>
        /// <param name="isBackground">Whether or not threads are a background threads</param>
        /// <param name="options">Additional thread pool creation parameters</param>
        private StaticThreadPool(StaticThreadPoolOptions options, int initialThreadCount, int queueBoundedCapacity, string name, bool isBackground)
            : base(queueBoundedCapacity, options.QueueStealAwakePeriod, isBackground, name, options.UseOwnTaskScheduler, options.UseOwnSyncContext, options.FlowExecutionContext)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (initialThreadCount < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(initialThreadCount));
            }
            if (options.MaxQueueCapacityExtension < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(options.MaxQueueCapacityExtension));
            }

            _maxQueueCapacityExtension = options.MaxQueueCapacityExtension > 0 ? options.MaxQueueCapacityExtension : 0;
            _queueBlockedCheckPeriod   = options.QueueBlockedCheckPeriod > 0 ? options.QueueBlockedCheckPeriod : 0;

            _wasSomeProcessByThreadsFlag = false;

            if (queueBoundedCapacity > 0 && _maxQueueCapacityExtension > 0 && _queueBlockedCheckPeriod > 0)
            {
                Qoollo.Turbo.Threading.ServiceStuff.ManagementThreadController.Instance.RegisterCallback(ManagementThreadProc);
            }

            AddThreads(initialThreadCount);
        }
コード例 #2
0
 /// <summary>
 /// <see cref="StaticThreadPool"/> constructor
 /// </summary>
 /// <param name="initialThreadCount">Initial number of threads in ThreadPool</param>
 /// <param name="queueBoundedCapacity">The bounded size of the work items queue (if less or equal to 0 then no limitation)</param>
 /// <param name="name">The name for this instance of ThreadPool and for its threads</param>
 /// <param name="isBackground">Whether or not threads are a background threads</param>
 /// <param name="options">Additional thread pool creation parameters</param>
 public StaticThreadPool(int initialThreadCount, int queueBoundedCapacity, string name, bool isBackground, StaticThreadPoolOptions options)
     : this(options ?? StaticThreadPoolOptions.Default, initialThreadCount, queueBoundedCapacity, name, isBackground)
 {
 }