Example #1
0
        private void AddTimerNode(TimerNode node)
        {
            var expire = node.ExpireTick;

            if (expire < index)
            {
                throw new Exception();
            }

            // expire equals index at higher 24bits
            if ((expire | TimeNearMask) == (index | TimeNearMask))
            {
                nearTimerNodes[expire & TimeNearMask].AddLast(node);
            }
            else
            {
                var shift = TimeNearShift;

                for (int i = 0; i < 4; i++)
                {
                    var lowerMask = (1 << (shift + TimeLevelShift)) - 1;

                    // expire equals index at higher (24-6*(i+1))bits
                    if ((expire | lowerMask) == (index | lowerMask))
                    {
                        // take out [(8+i*6), (14+i*6)) of the bits
                        levelTimerNodes[i][(expire >> shift) & TimeLevelMask].AddLast(node);
                        break;
                    }

                    shift += TimeLevelShift;
                }
            }
        }
Example #2
0
        public ITimer AddTimer(uint afterTick, OnTimerTimeout callback, params object[] userData)
        {
            var expireTick = afterTick + index;
            var node       = new TimerNode()
            {
                ExpireTick = expireTick,
                Callback   = callback,
                UserData   = userData,
            };

            AddTimerNode(node);

            return(node);
        }
        public ITimer AddTimer(uint afterTick, OnTimerTimeout callback, params object[] userData)
        {
            var expireTick = afterTick + index;
            var node = new TimerNode()
            {
                ExpireTick = expireTick,
                Callback = callback,
                UserData = userData,
            };

            AddTimerNode(node);

            return node;
        }
        private void AddTimerNode(TimerNode node)
        {
            var expire = node.ExpireTick;

            if (expire < index)
            {
                throw new Exception();
            }

            // expire equals index at higher 24bits 
            if ((expire | TimeNearMask) == (index | TimeNearMask))
            {
                nearTimerNodes[expire & TimeNearMask].AddLast(node);
            }
            else
            {
                var shift = TimeNearShift;

                for (int i = 0; i < 4; i++)
                {
                    var lowerMask = (1 << (shift+TimeLevelShift))-1;

                    // expire equals index at higher (24-6*(i+1))bits 
                    if ((expire | lowerMask) == (index | lowerMask))
                    {
                        // take out [(8+i*6), (14+i*6)) of the bits
                        levelTimerNodes[i][(expire >> shift)&TimeLevelMask].AddLast(node);
                        break;
                    }

                    shift += TimeLevelShift;
                }
            }
        }