コード例 #1
0
        // 转轮
        public void Turn()
        {
            if (smallerWheel == null)
            {
                return;
            }

            TimerList nowList = array[index++];

            Timer head = nowList.head;
            Timer nextTimer;

            while (head != null)
            {
                nextTimer = head.next;
                smallerWheel.AddTimer(head);
                head = nextTimer;
                timerCount--;
            }

            nowList.head = null;
            nowList.tail = null;
            baseTick    += msUint;

            if (index == 0 && biggerWheel != null)
            {
                biggerWheel.Turn();
            }
        }
コード例 #2
0
 public TimerListWheel()
 {
     for (int i = 0; i < arraySize; i++)
     {
         array[i] = new TimerList();
     }
 }
コード例 #3
0
        public Timer GetTimer(UInt64 runTick, uint timerSeqID)
        {
            if (smallerWheel != null && (runTick < baseTick))
            {
                return(smallerWheel.GetTimer(runTick, timerSeqID));
            }

            byte      idx      = (byte)(index + TickIdxDelta(runTick));
            TimerList currList = array[idx];

            return(currList.GetTimer(timerSeqID));
        }
コード例 #4
0
        public void AddTimer(Timer timer)
        {
            if (smallerWheel != null && (timer.runTick < baseTick))
            {
                smallerWheel.AddTimer(timer);
                return;
            }

            byte      idx      = (byte)(index + TickIdxDelta(timer.runTick));
            TimerList currList = array[idx];

            currList.AddTimer(timer);
            timerCount++;
        }
コード例 #5
0
        public bool DeleteTimer(UInt64 runTick, uint timerSeqID)
        {
            if (smallerWheel != null && (runTick < baseTick))
            {
                return(smallerWheel.DeleteTimer(runTick, timerSeqID));
            }

            byte      idx      = (byte)(index + TickIdxDelta(runTick));
            TimerList currList = array[idx];

            if (!currList.DeleteTimer(timerSeqID))
            {
                sLog.Error("timer_manager", (new System.Diagnostics.StackTrace()).ToString());
                sLog.Error("timer_manager", "DeleteTimer Error : runTick:" + runTick + ",seqID:" + timerSeqID + ",index:" + index + ",idx:" + idx);
                return(false);
            }
            timerCount--;
            return(true);
        }
コード例 #6
0
        public bool Execute(UInt64 now, ref int maxCount)
        {
            if (smallerWheel != null)
            {
                return(false);
            }

            UInt64 elapsedTime = now - baseTick;
            UInt64 loopTimes   = 1 + elapsedTime;

            byte nowIndex = index;

            index    += (byte)(elapsedTime);
            baseTick += elapsedTime;

            int  tempCount;
            bool ret = false;

            while (maxCount > 0)
            {
                loopTimes--;

                TimerList nowList = array[nowIndex];
                tempCount   = maxCount;
                ret         = ret | nowList.Execute(now, ref maxCount);
                timerCount -= tempCount - maxCount;

                if (loopTimes <= 0)
                {
                    break;
                }
                if ((++nowIndex) == 0)
                {
                    biggerWheel.Turn();
                }
            }
            return(ret);
        }