protected LoopExecutor(IEventLoopGroup parent, IThreadFactory threadFactory, IRejectedExecutionHandler rejectedHandler, TimeSpan breakoutInterval) : base(parent, threadFactory, false, int.MaxValue, rejectedHandler) { _writeRequestPool = new ThreadLocalPool <WriteRequest>(s_valueFactory); _preciseBreakoutInterval = ToPreciseTime(breakoutInterval); _loop = new Loop(); _asyncHandle = new Async(_loop, OnCallbackAction, this); _timerHandle = new Timer(_loop, OnCallbackAction, this); _loopRunStart = new ManualResetEventSlim(false, 1); if (SharedConstants.False >= (uint)Interlocked.Exchange(ref s_startTimeInitialized, SharedConstants.True)) { _loop.UpdateTime(); s_initialTime = _loop.Now; } }
public LoopExecutor(IEventLoopGroup parent, string threadName, TimeSpan breakoutInterval) : base(parent) { this.preciseBreakoutInterval = (long)breakoutInterval.TotalMilliseconds; this.terminationCompletionSource = new TaskCompletionSource(); this.taskQueue = PlatformDependent.NewMpscQueue <IRunnable>(); this.scheduler = new ExecutorTaskScheduler(this); this.loop = new Loop(); this.asyncHandle = new Async(this.loop, OnCallback, this); this.timerHandle = new Timer(this.loop, OnCallback, this); string name = $"{this.GetType().Name}:{this.loop.Handle}"; if (!string.IsNullOrEmpty(threadName)) { name = $"{name}({threadName})"; } this.thread = new XThread(Run) { Name = name }; this.loopRunStart = new ManualResetEventSlim(false, 1); }
public LoopExecutor(IEventLoopGroup parent, string threadName, TimeSpan breakoutInterval) : base(parent) { this.preciseBreakoutInterval = PreciseTimeSpan.FromTimeSpan(breakoutInterval); this.preciseTimerInterval = PreciseTimeSpan.FromTimeSpan(TimeSpan.FromTicks(breakoutInterval.Ticks * 2)); this.terminationCompletionSource = new TaskCompletionSource(); this.taskQueue = PlatformDependent.NewMpscQueue <IRunnable>(); this.scheduler = new ExecutorTaskScheduler(this); this.loop = new Loop(); this.asyncHandle = new Async(this.loop, RunAllTasksCallback, this); this.timerHandle = new Timer(this.loop, RunAllTasksCallback, this); string name = string.Format(DefaultWorkerThreadName, this.loop.Handle); if (!string.IsNullOrEmpty(threadName)) { name = $"{name} ({threadName})"; } this.thread = new XThread(RunLoop) { Name = name }; }