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
parent 809f9b4976
commit fb4bc652e0
2 changed files with 23 additions and 0 deletions

View File

@ -45,6 +45,8 @@ DiscardTimeoutChangedCallback(const char* aPref, void *aClosure)
nsresult nsresult
DiscardTracker::Reset(Node *node) DiscardTracker::Reset(Node *node)
{ {
EnsureMainThread();
// We shouldn't call Reset() with a null |img| pointer, on images which can't // 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 // be discarded, or on animated images (which should be marked as
// non-discardable, anyway). // non-discardable, anyway).
@ -84,6 +86,8 @@ DiscardTracker::Reset(Node *node)
void void
DiscardTracker::Remove(Node *node) DiscardTracker::Remove(Node *node)
{ {
EnsureMainThread();
if (node->isInList()) if (node->isInList())
node->remove(); node->remove();
@ -97,6 +101,8 @@ DiscardTracker::Remove(Node *node)
void void
DiscardTracker::Shutdown() DiscardTracker::Shutdown()
{ {
EnsureMainThread();
if (sTimer) { if (sTimer) {
sTimer->Cancel(); sTimer->Cancel();
sTimer = NULL; sTimer = NULL;
@ -109,6 +115,8 @@ DiscardTracker::Shutdown()
void void
DiscardTracker::DiscardAll() DiscardTracker::DiscardAll()
{ {
EnsureMainThread();
if (!sInitialized) if (!sInitialized)
return; return;
@ -126,6 +134,8 @@ DiscardTracker::DiscardAll()
void void
DiscardTracker::InformAllocation(PRInt64 bytes) DiscardTracker::InformAllocation(PRInt64 bytes)
{ {
EnsureMainThread();
// This function is called back e.g. from RasterImage::Discard(); be careful! // This function is called back e.g. from RasterImage::Discard(); be careful!
sCurrentDecodedImageBytes += bytes; sCurrentDecodedImageBytes += bytes;
@ -136,6 +146,17 @@ DiscardTracker::InformAllocation(PRInt64 bytes)
MaybeDiscardSoon(); 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. * Initialize the tracker.
*/ */

View File

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