/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
nsresult AddTimer(nsTimerImpl* aTimer, const MutexAutoLock& aProofOfLock)
MOZ_REQUIRES(aTimer->mMutex);
nsresult RemoveTimer(nsTimerImpl* aTimer, const MutexAutoLock& aProofOfLock)
MOZ_REQUIRES(aTimer->mMutex); // Considering only the first 'aSearchBound' timers (in firing order), returns // the timeout of the first non-low-priority timer, on the current thread, // that will fire before 'aDefault'. If no such timer exists, 'aDefault' is // returned.
TimeStamp FindNextFireTimeForCurrentThread(TimeStamp aDefault,
uint32_t aSearchBound);
// These internal helper methods must be called while mMonitor is held. // AddTimerInternal returns false if the insertion failed. bool AddTimerInternal(nsTimerImpl& aTimer) MOZ_REQUIRES(mMonitor); bool RemoveTimerInternal(nsTimerImpl& aTimer)
MOZ_REQUIRES(mMonitor, aTimer.mMutex); void RemoveLeadingCanceledTimersInternal() MOZ_REQUIRES(mMonitor); void RemoveFirstTimerInternal() MOZ_REQUIRES(mMonitor);
nsresult Init() MOZ_REQUIRES(mMonitor);
// Using atomic because this value is written to in one place, and read from // in another, and those two locations are likely to be executed from separate // threads. Reads/writes to an aligned value this size should be atomic even // without using std::atomic, but doing this explicitly provides a good // reminder that this is accessed from multiple threads.
std::atomic<mozilla::hal::ProcessPriority> mCachedPriority =
mozilla::hal::PROCESS_PRIORITY_UNKNOWN;
// Called with the Monitor held, but not the TimerImpl's mutex
already_AddRefed<nsTimerImpl> Take() { if (MOZ_LIKELY(mTimerImpl)) {
MOZ_ASSERT(mTimerImpl->IsInTimerThread());
mTimerImpl->SetIsInTimerThread(false);
} return mTimerImpl.forget();
}
private: // These values are simply cached from the timer. Keeping them here is good // for cache usage and allows us to avoid worrying about locking conflicts // with the timer.
TimeStamp mTimeout;
TimeDuration mDelay;
RefPtr<nsTimerImpl> mTimerImpl;
};
// Computes and returns the index in mTimers at which a new timer with the // specified timeout should be inserted in order to maintain "sorted" order.
size_t ComputeTimerInsertionIndex(const TimeStamp& timeout) const
MOZ_REQUIRES(mMonitor);
// Computes and returns when we should next try to wake up in order to handle // the triggering of the timers in mTimers. Currently this is very simple and // we always just plan to wake up for the next timer in the list. In the // future this will be more sophisticated.
TimeStamp ComputeWakeupTimeFromTimers() const MOZ_REQUIRES(mMonitor);
// Computes how late a timer can acceptably fire. // timerDuration is the duration of the timer whose delay we are calculating. // Longer timers can tolerate longer firing delays. // minDelay is an amount by which any timer can be delayed. // This function will never return a value smaller than minDelay (unless this // conflicts with maxDelay). maxDelay is the upper limit on the amount by // which we will ever delay any timer. Takes precedence over minDelay if there // is a conflict. (Zero will effectively disable timer coalescing.)
TimeDuration ComputeAcceptableFiringDelay(TimeDuration timerDuration,
TimeDuration minDelay,
TimeDuration maxDelay) const;
#ifdef DEBUG // Checks mTimers to see if any entries are out of order or any cached // timeouts are incorrect and will assert if any inconsistency is found. Has // no side effects other than asserting so has no use in non-DEBUG builds. void VerifyTimerListConsistency() const MOZ_REQUIRES(mMonitor); #endif
// mTimers is maintained in a "pseudo-sorted" order wrt the timeouts. // Specifcally, mTimers is sorted according to the timeouts *if you ignore the // canceled entries* (those whose mTimerImpl is nullptr). Notably this means // that you cannot use a binary search on this list.
nsTArray<Entry> mTimers MOZ_GUARDED_BY(mMonitor);
// Set only at the start of the thread's Run():
uint32_t mAllowedEarlyFiringMicroseconds MOZ_GUARDED_BY(mMonitor);
// Time at which we were intending to wake up the last time that we slept. // Is "null" if we have never slept or if our last sleep was "forever".
TimeStamp mIntendedWakeupTime;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.