Exemplo n.º 1
0
        public LinkedNode Split()
        {
            var node = Next;

            Prev.Next = Next;
            Next.Prev = Prev;
            Next      = this;
            Prev      = this;

            return(node);
        }
Exemplo n.º 2
0
            public TimerWheel()
            {
                for (int i = 0; i < _firstWheel.Length; ++i)
                {
                    _firstWheel[i] = new LinkedNode();
                }
                for (int i = 0; i < kNWheelCount; ++i)
                {
                    _NWheel[i] = new LinkedNode[kNCount];

                    for (int j = 0; j < kNCount; ++j)
                    {
                        _NWheel[i][j] = new LinkedNode();
                    }
                }
            }
Exemplo n.º 3
0
 public void Tick()
 {
     if (0 == (_currentTick & kFirstMask))
     {
         int i     = 0;
         int index = 0;
         do
         {
             index = GetNthIndex(_currentTick, i + 1);
             _head = _NWheel[i][index];
             if (_head != _head.Next)
             {
                 var node = _head.Split();
                 while (node != node.Next)
                 {
                     var next = node.Split();
                     AddTimer((TimerEvent)node);
                     node = next;
                 }
                 AddTimer((TimerEvent)node);
             }
         } while (index == 0 && ++i < kNWheelCount);
     }
     _head = _firstWheel[_currentTick & kFirstMask];
     if (_head != _head.Next)
     {
         var node = _head;
         while (_head != node.Next)
         {
             var te = (TimerEvent)node.Next;
             if (null != te.Callback)
             {
                 te.Callback();
             }
             node = node.Next;
             _teNodePool.Release(te);
         }
         _head.Reset();
     }
 }
Exemplo n.º 4
0
 public void Reset()
 {
     Next = this;
     Prev = this;
 }
Exemplo n.º 5
0
 public LinkedNode()
 {
     Next = this;
     Prev = this;
 }