Ejemplo n.º 1
0
 //-------------------------------------------------------------------------
 // 添加一个节点
 void _addNode(EbDoubleLinkNode <TObject> pnew, EbDoubleLinkNode <TObject> prev, EbDoubleLinkNode <TObject> next)
 {
     next.prev = pnew;
     pnew.next = next;
     pnew.prev = prev;
     prev.next = pnew;
 }
Ejemplo n.º 2
0
 //-------------------------------------------------------------------------
 // 替换一个节点
 public void replaceNode(EbDoubleLinkNode <TObject> old, EbDoubleLinkNode <TObject> pnew)
 {
     pnew.next      = old.next;
     pnew.next.prev = pnew;
     pnew.prev      = old.prev;
     pnew.prev.next = pnew;
 }
Ejemplo n.º 3
0
 //-------------------------------------------------------------------------
 // 删除一个节点
 static void _delNode(EbDoubleLinkNode <TObject> prev, EbDoubleLinkNode <TObject> next)
 {
     if (prev != null && next != null)
     {
         next.prev = prev;
         prev.next = next;
     }
 }
Ejemplo n.º 4
0
        //-------------------------------------------------------------------------
        // 添加一个时间事件
        public void addTimer(EbTimeEvent time_event)
        {
            EbDoubleLinkNode <EbTimeEvent> timer_node = new EbDoubleLinkNode <EbTimeEvent>();

            timer_node.mObject = time_event;

            mMapEventNode[time_event] = timer_node;

            _addTimer(timer_node);
        }
Ejemplo n.º 5
0
        //-------------------------------------------------------------------------
        // 删除一个时间事件
        public int delTimer(EbTimeEvent time_event)
        {
            if (mMapEventNode.ContainsKey(time_event))
            {
                EbDoubleLinkNode <EbTimeEvent> timer_node = mMapEventNode[time_event];

                _delTimer(timer_node);
            }

            return(0);
        }
Ejemplo n.º 6
0
        //-------------------------------------------------------------------------
        // 添加事件
        void _addTimer(EbDoubleLinkNode <EbTimeEvent> timer)
        {
            ulong expires = timer.mObject.mExpires;

            ulong idx = expires - mTimeJeffies;

            EbDoubleLinkList <EbTimeEvent> list_timer_spoke = null;

            if (idx < MAX_WHEEL_SIZE)
            {// 第1个轮子
                ulong i = expires & MAX_WHEEL_MASK;
                list_timer_spoke = mWheel1.mListTimerSpoke[(int)i];
            }
            else if (idx < (ulong)1 << Convert.ToInt32(MAX_WHEEL + MIN_WHEEL))
            {// 第2个轮子
                ulong i = expires >> Convert.ToInt32(MAX_WHEEL) & MIN_WHEEL_MASK;
                list_timer_spoke = mWheel2.mListTimerSpoke[(int)i];
            }
            else if (idx < (ulong)1 << Convert.ToInt32(MAX_WHEEL + 2 * MIN_WHEEL))
            {// 第3个轮子
                ulong i = expires >> Convert.ToInt32(MAX_WHEEL + MIN_WHEEL) & MIN_WHEEL_MASK;
                list_timer_spoke = mWheel3.mListTimerSpoke[(int)i];
            }
            else if (idx < (ulong)1 << Convert.ToInt32(MAX_WHEEL + 3 * MIN_WHEEL))
            {// 第4个轮子
                ulong i = expires >> Convert.ToInt32(MAX_WHEEL + 2 * MIN_WHEEL) & MIN_WHEEL_MASK;
                list_timer_spoke = mWheel4.mListTimerSpoke[(int)i];
            }
            else if ((long)idx < 0)
            {
                // Can happen if you add a timer with expires == jiffies,
                // or you set a timer to go off in the past
                list_timer_spoke = mWheel1.mListTimerSpoke[(int)(mTimeJeffies & MAX_WHEEL_MASK)];
            }
            else
            {
                // If the timeout is larger than 0xffffffff on 64-bit
                // architectures then we use the maximum timeout:
                if (idx > 0xffffffffUL)
                {
                    idx     = 0xffffffffUL;
                    expires = idx + mTimeJeffies;
                }
                ulong i = expires >> Convert.ToInt32(MAX_WHEEL + 3 * MIN_WHEEL) & MIN_WHEEL_MASK;
                list_timer_spoke = mWheel5.mListTimerSpoke[(int)i];
            }

            // Timers are FIFO:
            list_timer_spoke.addTailNode(timer);
        }
Ejemplo n.º 7
0
        //-------------------------------------------------------------------------
        // 添加队列到本队列(队尾)
        public void addTailList(EbDoubleLinkList <TObject> plist)
        {
            if (!plist.empty())
            {
                EbDoubleLinkNode <TObject> add_list_first = plist.firstNode();
                EbDoubleLinkNode <TObject> add_list_last  = plist.lastNode();
                plist.init();

                EbDoubleLinkNode <TObject> list_last = lastNode();
                list_last.next      = add_list_first;
                add_list_first.prev = list_last;
                add_list_last.next  = mpHead;
                mpHead.prev         = add_list_last;
            }
        }
Ejemplo n.º 8
0
        //-------------------------------------------------------------------------
        public void destroy()
        {
            EbDoubleLinkNode <TObject> pnode = mpHead.next;

            do
            {
                if (pnode != mpHead)
                {
                    // 删除结点
                    delNode(pnode);

                    pnode = mpHead.next;
                }
            } while (pnode != mpHead);
        }
Ejemplo n.º 9
0
        //-------------------------------------------------------------------------
        // 取得队列节点个数
        public uint getNodeCount()
        {
            EbDoubleLinkNode <TObject> pnode = mpHead.next;
            uint count = 0;

            do
            {
                if (pnode != mpHead)
                {
                    count++;
                    pnode = mpHead.next;
                }
            } while (pnode != mpHead);

            return(count);
        }
Ejemplo n.º 10
0
 //-------------------------------------------------------------------------
 // 删除一个节点
 public static void delNode(EbDoubleLinkNode <TObject> entry)
 {
     _delNode(entry.prev, entry.next);
     entry.next = null;
     entry.prev = null;
 }
Ejemplo n.º 11
0
 //-------------------------------------------------------------------------
 // 向队尾添加一个节点
 public void addTailNode(EbDoubleLinkNode <TObject> pnew)
 {
     _addNode(pnew, mpHead.prev, mpHead);
 }
Ejemplo n.º 12
0
 //-------------------------------------------------------------------------
 // 向对头添加一个节点
 public void addNode(EbDoubleLinkNode <TObject> pnew)
 {
     _addNode(pnew, mpHead, mpHead.next);
 }
Ejemplo n.º 13
0
 //-------------------------------------------------------------------------
 // 取得上一个节点
 public EbDoubleLinkNode <TObject> prevNode(EbDoubleLinkNode <TObject> pnode)
 {
     return(pnode.prev);
 }
Ejemplo n.º 14
0
 //-------------------------------------------------------------------------
 // 取得下一个节点
 public EbDoubleLinkNode <TObject> nextNode(EbDoubleLinkNode <TObject> pnode)
 {
     return(pnode.next);
 }
Ejemplo n.º 15
0
 //-------------------------------------------------------------------------
 public EbDoubleLinkList()
 {
     mpHead = new EbDoubleLinkNode <TObject>();
     init();
 }
Ejemplo n.º 16
0
        //-------------------------------------------------------------------------
        // 删除事件
        int _delTimer(EbDoubleLinkNode <EbTimeEvent> timer)
        {
            EbDoubleLinkList <EbTimeEvent> .delNode(timer);

            return(0);
        }
Ejemplo n.º 17
0
 //-------------------------------------------------------------------------
 // 最后一个节点
 public bool isLast(EbDoubleLinkNode <TObject> list)
 {
     return(list.next == mpHead);
 }