Bug 745662 - Trigger a fatal release-time crash when the discard tracker is used off the main thread. r=joe

This commit is contained in:
Justin Lebar 2012-04-18 11:30:42 +10:00
Родитель 0ba3045c86
Коммит 7fe7250e5e
2 изменённых файлов: 23 добавлений и 0 удалений

Просмотреть файл

@ -45,6 +45,8 @@ DiscardTimeoutChangedCallback(const char* aPref, void *aClosure)
nsresult
DiscardTracker::Reset(Node *node)
{
EnsureMainThread();
// We shouldn't call Reset() with a null |img| pointer, on images which can't
// be discarded, or on animated images (which should be marked as
// non-discardable, anyway).
@ -84,6 +86,8 @@ DiscardTracker::Reset(Node *node)
void
DiscardTracker::Remove(Node *node)
{
EnsureMainThread();
if (node->isInList())
node->remove();
@ -97,6 +101,8 @@ DiscardTracker::Remove(Node *node)
void
DiscardTracker::Shutdown()
{
EnsureMainThread();
if (sTimer) {
sTimer->Cancel();
sTimer = NULL;
@ -109,6 +115,8 @@ DiscardTracker::Shutdown()
void
DiscardTracker::DiscardAll()
{
EnsureMainThread();
if (!sInitialized)
return;
@ -126,6 +134,8 @@ DiscardTracker::DiscardAll()
void
DiscardTracker::InformAllocation(PRInt64 bytes)
{
EnsureMainThread();
// This function is called back e.g. from RasterImage::Discard(); be careful!
sCurrentDecodedImageBytes += bytes;
@ -136,6 +146,17 @@ DiscardTracker::InformAllocation(PRInt64 bytes)
MaybeDiscardSoon();
}
void
DiscardTracker::EnsureMainThread()
{
// NS_RUNTIMEABORT is a fatal crash even in release builds. We need to crash
// release builds here in order to investigate bug 745141 -- we're being
// called from off main thread, but we don't know how!
if (!NS_IsMainThread()) {
NS_RUNTIMEABORT("Must be on main thread!");
}
}
/**
* Initialize the tracker.
*/

Просмотреть файл

@ -100,6 +100,8 @@ class DiscardTracker
static void TimerCallback(nsITimer *aTimer, void *aClosure);
static void DiscardNow();
static void EnsureMainThread();
static LinkedList<Node> sDiscardableImages;
static nsCOMPtr<nsITimer> sTimer;
static bool sInitialized;