Skip to content

Commit

Permalink
Bug 887466 - Rearrange SyncDecode so that we never try to finish a si…
Browse files Browse the repository at this point in the history
…ze decode with the decode lock held. r=seth
  • Loading branch information
joedrew committed Jul 26, 2013
1 parent 01490a0 commit ec74dff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
36 changes: 18 additions & 18 deletions image/src/RasterImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2325,26 +2325,8 @@ RasterImage::RequestDecodeCore(RequestDecodeType aDecodeType)
nsresult
RasterImage::SyncDecode()
{
MutexAutoLock imgLock(mDecodingMutex);

if (mDecodeRequest) {
// If the image is waiting for decode work to be notified, go ahead and do that.
if (mDecodeRequest->mRequestStatus == DecodeRequest::REQUEST_WORK_DONE) {
nsresult rv = FinishedSomeDecoding();
CONTAINER_ENSURE_SUCCESS(rv);
}
}

nsresult rv;

PROFILER_LABEL_PRINTF("RasterImage", "SyncDecode", "%s", GetURIString().get());;

// We really have no good way of forcing a synchronous decode if we're being
// called in a re-entrant manner (ie, from an event listener fired by a
// decoder), because the decoding machinery is already tied up. We thus explicitly
// disallow this type of call in the API, and check for it in API methods.
NS_ABORT_IF_FALSE(!mInDecoder, "Yikes, forcing sync in reentrant call!");

// If we have a size decoder open, make sure we get the size
if (mDecoder && mDecoder->IsSizeDecode()) {
nsresult rv = DecodePool::Singleton()->DecodeUntilSizeAvailable(this);
Expand All @@ -2358,6 +2340,24 @@ RasterImage::SyncDecode()
}
}

MutexAutoLock imgLock(mDecodingMutex);

// We really have no good way of forcing a synchronous decode if we're being
// called in a re-entrant manner (ie, from an event listener fired by a
// decoder), because the decoding machinery is already tied up. We thus explicitly
// disallow this type of call in the API, and check for it in API methods.
NS_ABORT_IF_FALSE(!mInDecoder, "Yikes, forcing sync in reentrant call!");

if (mDecodeRequest) {
// If the image is waiting for decode work to be notified, go ahead and do that.
if (mDecodeRequest->mRequestStatus == DecodeRequest::REQUEST_WORK_DONE) {
nsresult rv = FinishedSomeDecoding();
CONTAINER_ENSURE_SUCCESS(rv);
}
}

nsresult rv;

// If we're decoded already, or decoding until the size was available
// finished us as a side-effect, no worries
if (mDecoded)
Expand Down
2 changes: 1 addition & 1 deletion image/src/RasterImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,9 @@ class RasterImage : public ImageResource
nsRefPtr<Decoder> mDecoder;
nsRefPtr<DecodeRequest> mDecodeRequest;
uint32_t mBytesDecoded;
// END LOCKED MEMBER VARIABLES

bool mInDecoder;
// END LOCKED MEMBER VARIABLES

// Boolean flags (clustered together to conserve space):
bool mHasSize:1; // Has SetSize() been called?
Expand Down

0 comments on commit ec74dff

Please sign in to comment.