예제 #1
0
 private int AddTimer(TimerTask p)
 {
     lock (mQueueLock)
     {
         mPriorityQueue.Enqueue(p.TimerId, p, p.NextTick);
     }
     return(p.TimerId);
 }
예제 #2
0
        public int AddTimer <T>(int start, int interval, Action <T> handler, T arg1)
        {
            Callback1 <T> callback = ObjectPools.Instance.Acquire <Callback1 <T> >();

            callback.Arg1    = arg1;
            callback.Handler = handler;
            TimerTask p = GetTimerData(callback, start, interval);

            return(AddTimer(p));
        }
예제 #3
0
        private TimerTask GetTimerData(Callback callback, int start, int interval)
        {
            TimerTask task = ObjectPools.Instance.Acquire <TimerTask>();

            task.Callback = callback;
            task.Interval = interval;
            task.TimerId  = NextTimerId;
            task.NextTick = mCurrentTick + 1 + start;
            return(task);
        }
예제 #4
0
        public int AddTimer <T, U, V>(int start, int interval, Action <T, U, V> handler, T arg1, U arg2, V arg3)
        {
            Callback3 <T, U, V> callback = ObjectPools.Instance.Acquire <Callback3 <T, U, V> >();

            callback.Arg1    = arg1;
            callback.Arg2    = arg2;
            callback.Arg3    = arg3;
            callback.Handler = handler;
            TimerTask p = GetTimerData(callback, start, interval);

            return(AddTimer(p));
        }
예제 #5
0
        public void DelTimer(int timerId)
        {
            TimerTask p = null;

            lock (mQueueLock)
            {
                p = mPriorityQueue.Remove(timerId);
            }
            if (p != null)
            {
                ObjectPools.Instance.Release(p);
            }
        }
예제 #6
0
 public void Reset()
 {
     mCurrentTick = 0;
     mNextTimerId = 0;
     lock (mQueueLock)
     {
         while (mPriorityQueue.Size != 0)
         {
             TimerTask p = mPriorityQueue.Dequeue();
             ObjectPools.Instance.Release(p);
         }
     }
 }