コード例 #1
0
ファイル: Scheduler.cs プロジェクト: yusharth/psi
        /// <summary>
        /// Initializes a new instance of the <see cref="Scheduler"/> class.
        /// </summary>
        /// <param name="errorHandler">Error handler function.</param>
        /// <param name="threadCount">Scheduler thread count.</param>
        /// <param name="allowSchedulingOnExternalThreads">Allow scheduling on external threads.</param>
        /// <param name="name">Scheduler name.</param>
        /// <param name="clock">Optional clock to use (defaults to virtual time offset of DateTime.MinValue and dilation factor of 0).</param>
        public Scheduler(Func <Exception, bool> errorHandler, int threadCount = 0, bool allowSchedulingOnExternalThreads = false, string name = "default", Clock clock = null)
        {
            this.name            = name;
            this.errorHandler    = errorHandler;
            this.threadSemaphore = new SimpleSemaphore((threadCount == 0) ? Environment.ProcessorCount * 2 : threadCount);
            this.allowSchedulingOnExternalThreads = allowSchedulingOnExternalThreads;
            this.globalWorkitems = new WorkItemQueue(name);
            this.futureWorkitems = new FutureWorkItemQueue(name + "_future", this);

            // set virtual time such that any scheduled item appears to be in the future and gets queued in the future workitem queue
            // the time will change when the scheduler is started, and the future workitem queue will be drained then as appropriate
            this.clock = clock ?? new Clock(DateTime.MinValue, 0);
            this.delayFutureWorkitemsUntilDue = true;
        }
コード例 #2
0
        public Scheduler(DeliveryPolicy globalPolicy, Func <Exception, bool> errorHandler, int threadCount = 0, bool allowSchedulingOnExternalThreads = false, string name = "default")
        {
            this.globalPolicy    = globalPolicy;
            this.errorHandler    = errorHandler;
            this.threadSemaphore = new SimpleSemaphore((threadCount == 0) ? Environment.ProcessorCount * 2 : threadCount);
            this.allowSchedulingOnExternalThreads = allowSchedulingOnExternalThreads;
            this.globalWorkitems = new WorkItemQueue(name);
            this.futureWorkitems = new FutureWorkItemQueue(name + "_future", this);
            this.futuresThread   = new Thread(new ThreadStart(this.ProcessFutureQueue));
            Platform.Specific.SetApartmentState(this.futuresThread, ApartmentState.MTA);

            // set virtual time such that any scheduled item appears to be in the future and gets queued in the future workitem queue
            // the time will change when the scheduler is started, and the future workitem queue will be drained then as appropriate
            this.clock = new Clock(DateTime.MinValue, 0);
            this.delayFutureWorkitemsUntilDue = true;
        }