本文整理汇总了C++中Timeout::Release方法的典型用法代码示例。如果您正苦于以下问题:C++ Timeout::Release方法的具体用法?C++ Timeout::Release怎么用?C++ Timeout::Release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timeout
的用法示例。
在下文中一共展示了Timeout::Release方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InsertionPoint
nsresult
TimeoutManager::Timeouts::ResetTimersForThrottleReduction(int32_t aPreviousThrottleDelayMS,
int32_t aMinTimeoutValueMS,
SortBy aSortBy,
nsIEventTarget* aQueue)
{
TimeStamp now = TimeStamp::Now();
// If insertion point is non-null, we're in the middle of firing timers and
// the timers we're planning to fire all come before insertion point;
// insertion point itself is a dummy timeout with an When() that may be
// semi-bogus. In that case, we don't need to do anything with insertion
// point or anything before it, so should start at the timer after insertion
// point, if there is one.
// Otherwise, start at the beginning of the list.
for (Timeout* timeout = InsertionPoint() ?
InsertionPoint()->getNext() : GetFirst();
timeout; ) {
// It's important that this check be <= so that we guarantee that
// taking std::max with |now| won't make a quantity equal to
// timeout->When() below.
if (timeout->When() <= now) {
timeout = timeout->getNext();
continue;
}
if (timeout->When() - now >
TimeDuration::FromMilliseconds(aPreviousThrottleDelayMS)) {
// No need to loop further. Timeouts are sorted in When() order
// and the ones after this point were all set up for at least
// gMinBackgroundTimeoutValue ms and hence were not clamped.
break;
}
// We reduced our throttled delay. Re-init the timer appropriately.
// Compute the interval the timer should have had if it had not been set in a
// background window
TimeDuration interval =
TimeDuration::FromMilliseconds(std::max(timeout->mInterval,
uint32_t(aMinTimeoutValueMS)));
uint32_t oldIntervalMillisecs = 0;
timeout->mTimer->GetDelay(&oldIntervalMillisecs);
TimeDuration oldInterval = TimeDuration::FromMilliseconds(oldIntervalMillisecs);
if (oldInterval > interval) {
// unclamp
TimeStamp firingTime =
std::max(timeout->When() - oldInterval + interval, now);
NS_ASSERTION(firingTime < timeout->When(),
"Our firing time should strictly decrease!");
TimeDuration delay = firingTime - now;
timeout->SetWhenOrTimeRemaining(now, delay);
MOZ_DIAGNOSTIC_ASSERT(timeout->When() == firingTime);
// Since we reset When() we need to move |timeout| to the right
// place in the list so that it remains sorted by When().
// Get the pointer to the next timeout now, before we move the
// current timeout in the list.
Timeout* nextTimeout = timeout->getNext();
// It is safe to remove and re-insert because When() is now
// strictly smaller than it used to be, so we know we'll insert
// |timeout| before nextTimeout.
NS_ASSERTION(!nextTimeout ||
timeout->When() < nextTimeout->When(), "How did that happen?");
timeout->remove();
// Insert() will addref |timeout| and reset mFiringDepth. Make sure to
// undo that after calling it.
uint32_t firingDepth = timeout->mFiringDepth;
Insert(timeout, aSortBy);
timeout->mFiringDepth = firingDepth;
timeout->Release();
nsresult rv = timeout->InitTimer(aQueue, delay.ToMilliseconds());
if (NS_FAILED(rv)) {
NS_WARNING("Error resetting non background timer for DOM timeout!");
return rv;
}
timeout = nextTimeout;
} else {
timeout = timeout->getNext();
}
}
return NS_OK;
}
示例2: expiredIter
//.........这里部分代码省略.........
continue;
}
if (mWindow.IsSuspended()) {
// Some timer did suspend us. Make sure the
// rest of the timers get executed later.
timeout->mFiringDepth = 0;
continue;
}
// The timeout is on the list to run at this depth, go ahead and
// process it.
// Get the script context (a strong ref to prevent it going away)
// for this timeout and ensure the script language is enabled.
nsCOMPtr<nsIScriptContext> scx = mWindow.GetContextInternal();
if (!scx) {
// No context means this window was closed or never properly
// initialized for this language.
continue;
}
// This timeout is good to run
bool timeout_was_cleared = mWindow.RunTimeoutHandler(timeout, scx);
if (timeout_was_cleared) {
// Make sure the iterator isn't holding any Timeout objects alive.
runIter.Clear();
// The running timeout's window was cleared, this means that
// ClearAllTimeouts() was called from a *nested* call, possibly
// through a timeout that fired while a modal (to this window)
// dialog was open or through other non-obvious paths.
// Note that if the last expired timeout corresponding to each list
// is null, then we should expect a refcount of two, since the
// dummy timeout for this queue was never injected into it, and the
// corresponding timeoutExtraRef variable hasn't been cleared yet.
if (last_expired_timeout_is_normal) {
MOZ_ASSERT(dummy_normal_timeout->HasRefCnt(1), "dummy_normal_timeout may leak");
MOZ_ASSERT(dummy_tracking_timeout->HasRefCnt(2), "dummy_tracking_timeout may leak");
Unused << timeoutExtraRef1.forget().take();
} else {
MOZ_ASSERT(dummy_normal_timeout->HasRefCnt(2), "dummy_normal_timeout may leak");
MOZ_ASSERT(dummy_tracking_timeout->HasRefCnt(1), "dummy_tracking_timeout may leak");
Unused << timeoutExtraRef2.forget().take();
}
mNormalTimeouts.SetInsertionPoint(last_normal_insertion_point);
mTrackingTimeouts.SetInsertionPoint(last_tracking_insertion_point);
return;
}
// If we have a regular interval timer, we re-schedule the
// timeout, accounting for clock drift.
bool needsReinsertion = RescheduleTimeout(timeout, now, !aTimeout);
// Running a timeout can cause another timeout to be deleted, so
// we need to reset the pointer to the following timeout.
runIter.UpdateIterator();
timeout->remove();
if (needsReinsertion) {
// Insert interval timeout onto the corresponding list sorted in
// deadline order. AddRefs timeout.
if (runIter.PickedTrackingIter()) {
mTrackingTimeouts.Insert(timeout,
mWindow.IsFrozen() ? Timeouts::SortBy::TimeRemaining
: Timeouts::SortBy::TimeWhen);
} else {
mNormalTimeouts.Insert(timeout,
mWindow.IsFrozen() ? Timeouts::SortBy::TimeRemaining
: Timeouts::SortBy::TimeWhen);
}
}
// Release the timeout struct since it's possibly out of the list
timeout->Release();
}
}
// Take the dummy timeout off the head of the list
if (dummy_normal_timeout->isInList()) {
dummy_normal_timeout->remove();
}
timeoutExtraRef1 = nullptr;
MOZ_ASSERT(dummy_normal_timeout->HasRefCnt(1), "dummy_normal_timeout may leak");
if (dummy_tracking_timeout->isInList()) {
dummy_tracking_timeout->remove();
}
timeoutExtraRef2 = nullptr;
MOZ_ASSERT(dummy_tracking_timeout->HasRefCnt(1), "dummy_tracking_timeout may leak");
mNormalTimeouts.SetInsertionPoint(last_normal_insertion_point);
mTrackingTimeouts.SetInsertionPoint(last_tracking_insertion_point);
MaybeApplyBackPressure();
}