private void TimeoutCheck(CoroutineLockComponent self) { // 超时的锁 if (self.timers.Count == 0) { return; } long timeNow = TimeHelper.ClientFrameTime(); if (timeNow < self.minTime) { return; } foreach (KeyValuePair <long, List <CoroutineLockTimer> > kv in self.timers) { long k = kv.Key; if (k > timeNow) { self.minTime = k; break; } self.timeOutIds.Enqueue(k); } self.timerOutTimer.Clear(); while (self.timeOutIds.Count > 0) { long time = self.timeOutIds.Dequeue(); foreach (CoroutineLockTimer coroutineLockTimer in self.timers[time]) { self.timerOutTimer.Enqueue(coroutineLockTimer); } self.timers.Remove(time); } while (self.timerOutTimer.Count > 0) { CoroutineLockTimer coroutineLockTimer = self.timerOutTimer.Dequeue(); if (coroutineLockTimer.CoroutineLockInstanceId != coroutineLockTimer.CoroutineLock.InstanceId) { continue; } CoroutineLock coroutineLock = coroutineLockTimer.CoroutineLock; // 超时直接调用下一个锁 self.RunNextCoroutine(coroutineLock.coroutineLockType, coroutineLock.key, coroutineLock.level + 1); coroutineLock.coroutineLockType = CoroutineLockType.None; // 上面调用了下一个, dispose不再调用 } }
private void TimeoutCheck(CoroutineLockComponent self) { // 超时的锁 if (self.timers.Count == 0) { return; } self.timeNow = TimeHelper.ClientFrameTime(); if (self.timeNow < self.minTime) { return; } self.timers.ForEachFunc(self.foreachFunc); self.timerOutTimer.Clear(); while (self.timeOutIds.Count > 0) { long time = self.timeOutIds.Dequeue(); var list = self.timers[time]; for (int i = 0; i < list.Count; ++i) { CoroutineLockTimer coroutineLockTimer = list[i]; self.timerOutTimer.Enqueue(coroutineLockTimer); } self.timers.Remove(time); } while (self.timerOutTimer.Count > 0) { CoroutineLockTimer coroutineLockTimer = self.timerOutTimer.Dequeue(); if (coroutineLockTimer.CoroutineLockInstanceId != coroutineLockTimer.CoroutineLock.InstanceId) { continue; } CoroutineLock coroutineLock = coroutineLockTimer.CoroutineLock; // 超时直接调用下一个锁 self.RunNextCoroutine(coroutineLock.coroutineLockType, coroutineLock.key, coroutineLock.level + 1); coroutineLock.coroutineLockType = CoroutineLockType.None; // 上面调用了下一个, dispose不再调用 } }