public async Task TenK_WithTimerWheel() { TimerWheel wheel = TimerWheel.CreateTimerWheel(TimerWheelBenchmark.resolution, 20); List <Task> timers = new List <Task>(this.timeouts.Count); for (int i = 0; i < this.timeouts.Count; i++) { SimpleTimerWheel.TimerWheelTimer timer = wheel.CreateTimer(TimeSpan.FromMilliseconds(this.timeouts[i])); timers.Add(timer.StartTimerAsync()); } await Task.WhenAll(timers); wheel.Dispose(); }
public override void SubscribeForTimeouts(TimerWheelTimer timer) { this.ThrowIfDisposed(); long timerTimeoutInTicks = timer.Timeout.Ticks; int bucket = (int)timerTimeoutInTicks / this.resolutionInTicks; lock (this.subscriptionLock) { int index = this.GetIndexForTimeout(bucket); ConcurrentQueue <TimerWheelTimer> timerQueue = this.timers.GetOrAdd(index, _ => { return(new ConcurrentQueue <TimerWheelTimer>()); }); timerQueue.Enqueue(timer); } }
public abstract void SubscribeForTimeouts(TimerWheelTimer timer);