/// <summary>
 /// Resets all of the fields so this registration object can be used again
 /// </summary>
 public void Reset()
 {
     Next            = null;
     Prev            = null;
     Bucket          = null;
     Deadline        = 0;
     RemainingRounds = 0;
 }
 /// <summary>
 /// Slot a repeating task into the "reschedule" linked list.
 /// </summary>
 /// <param name="reg">The registration scheduled for repeating</param>
 public void Reschedule(SchedulerRegistration reg)
 {
     if (_rescheduleHead == null)
     {
         _rescheduleHead = _rescheduleTail = reg;
     }
     else
     {
         _rescheduleTail.Next = reg;
         reg.Prev             = _rescheduleTail;
         _rescheduleTail      = reg;
     }
 }
        private void PlaceInBucket(SchedulerRegistration reg)
        {
            var calculated = reg.Deadline / _tickDuration;

            reg.RemainingRounds = (calculated - _tick) / _wheel.Length;

            var ticks     = Math.Max(calculated, _tick); // Ensure we don't schedule for the past
            var stopIndex = (int)(ticks & _mask);

            var bucket = _wheel[stopIndex];

            bucket.AddRegistration(reg);
        }
        private void InternalSchedule(TimeSpan delay, TimeSpan interval, IRunnable action, ICancelable cancelable)
        {
            Start();
            var deadline = HighResMonotonicClock.Ticks + delay.Ticks - _startTime;
            var offset   = interval.Ticks;
            var reg      = new SchedulerRegistration(action, cancelable)
            {
                Deadline = deadline,
                Offset   = offset
            };

            _registrations.Enqueue(reg);
        }
 /// <summary>
 /// Adds a <see cref="SchedulerRegistration"/> to this bucket.
 /// </summary>
 /// <param name="reg">The scheduled task.</param>
 public void AddRegistration(SchedulerRegistration reg)
 {
     System.Diagnostics.Debug.Assert(reg.Bucket == null);
     reg.Bucket = this;
     if (_head == null) // first time the bucket has been used
     {
         _head = _tail = reg;
     }
     else
     {
         _tail.Next = reg;
         reg.Prev   = _tail;
         _tail      = reg;
     }
 }
            private SchedulerRegistration PollReschedule()
            {
                var head = _rescheduleHead;

                if (head == null)
                {
                    return(null);
                }
                var next = head.Next;

                if (next == null)
                {
                    _rescheduleTail = _rescheduleHead = null;
                }
                else
                {
                    _rescheduleHead = next;
                    next.Prev       = null;
                }

                head.Reset();
                return(head);
            }
            public void Remove(SchedulerRegistration reg)
            {
                var next = reg.Next;

                // Remove work that's already been completed or cancelled
                // Work that is scheduled to repeat will be handled separately
                if (reg.Prev != null)
                {
                    reg.Prev.Next = next;
                }
                if (reg.Next != null)
                {
                    reg.Next.Prev = reg.Prev;
                }

                if (reg == _head)
                {
                    // need to adjust the ends
                    if (reg == _tail)
                    {
                        _tail = null;
                        _head = null;
                    }
                    else
                    {
                        _head = next;
                    }
                }
                else if (reg == _tail)
                {
                    _tail = reg.Prev;
                }

                // detach the node from Linked list so it can be GCed
                reg.Reset();
            }
            public void Remove(SchedulerRegistration reg)
            {
                var next = reg.Next;

                // Remove work that's already been completed or cancelled
                // Work that is scheduled to repeat will be handled separately
                if (reg.Prev != null)
                {
                    reg.Prev.Next = next;
                }
                if (reg.Next != null)
                {
                    reg.Next.Prev = reg.Prev;
                }

                if (reg == _head)
                {
                    // need to adjust the ends
                    if (reg == _tail)
                    {
                        _tail = null;
                        _head = null;
                    }
                    else
                    {
                        _head = next;
                    }
                }
                else if (reg == _tail)
                {
                    _tail = reg.Prev;
                }

                // detach the node from Linked list so it can be GCed
                reg.Reset();
            }
            private SchedulerRegistration PollReschedule()
            {
                var head = _rescheduleHead;
                if (head == null)
                {
                    return null;
                }
                var next = head.Next;
                if (next == null)
                {
                    _rescheduleTail = _rescheduleHead = null;
                }
                else
                {
                    _rescheduleHead = next;
                    next.Prev = null;
                }

                head.Reset();
                return head;
            }
Exemplo n.º 10
0
 /// <summary>
 /// Slot a repeating task into the "reschedule" linked list.
 /// </summary>
 /// <param name="reg">The registration scheduled for repeating</param>
 public void Reschedule(SchedulerRegistration reg)
 {
     if (_rescheduleHead == null)
     {
         _rescheduleHead = _rescheduleTail = reg;
     }
     else
     {
         _rescheduleTail.Next = reg;
         reg.Prev = _rescheduleTail;
         _rescheduleTail = reg;
     }
 }
Exemplo n.º 11
0
 /// <summary>
 /// Adds a <see cref="SchedulerRegistration"/> to this bucket.
 /// </summary>
 /// <param name="reg">The scheduled task.</param>
 public void AddRegistration(SchedulerRegistration reg)
 {
     System.Diagnostics.Debug.Assert(reg.Bucket == null);
     reg.Bucket = this;
     if (_head == null) // first time the bucket has been used
     {
         _head = _tail = reg;
     }
     else
     {
         _tail.Next = reg;
         reg.Prev = _tail;
         _tail = reg;
     }
 }
Exemplo n.º 12
0
 /// <summary>
 /// Resets all of the fields so this registration object can be used again
 /// </summary>
 public void Reset()
 {
     Next = null;
     Prev = null;
     Bucket = null;
     Deadline = 0;
     RemainingRounds = 0;
 }
Exemplo n.º 13
0
 private void InternalSchedule(TimeSpan delay, TimeSpan interval, IRunnable action, ICancelable cancelable)
 {
     Start();
     var deadline = HighResMonotonicClock.Ticks + delay.Ticks - _startTime;
     var offset = interval.Ticks;
     var reg = new SchedulerRegistration(action, cancelable)
     {
         Deadline = deadline,
         Offset = offset
     };
     _registrations.Enqueue(reg);
 }
Exemplo n.º 14
0
        private void PlaceInBucket(SchedulerRegistration reg)
        {
            var calculated = reg.Deadline / _tickDuration;
            reg.RemainingRounds = (calculated - _tick) / _wheel.Length;

            var ticks = Math.Max(calculated, _tick); // Ensure we don't schedule for the past
            var stopIndex = (int)(ticks & _mask);

            var bucket = _wheel[stopIndex];
            bucket.AddRegistration(reg);
        }