private int AddTimer(TimerTask p) { lock (mQueueLock) { mPriorityQueue.Enqueue(p.TimerId, p, p.NextTick); } return(p.TimerId); }
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)); }
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); }
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)); }
public void DelTimer(int timerId) { TimerTask p = null; lock (mQueueLock) { p = mPriorityQueue.Remove(timerId); } if (p != null) { ObjectPools.Instance.Release(p); } }
public void Reset() { mCurrentTick = 0; mNextTimerId = 0; lock (mQueueLock) { while (mPriorityQueue.Size != 0) { TimerTask p = mPriorityQueue.Dequeue(); ObjectPools.Instance.Release(p); } } }