Bug 1293577 - Part 2. Add mutex to MetadataDecodingTask to protect from decoding races. r=seth
authorAndrew Osmond <aosmond@mozilla.com>
Thu, 18 Aug 2016 10:23:42 -0400
changeset 353627 3eade32e18c4446960aebf28039c6d116d63e255
parent 353626 c3b6a4e0898f39d882da2ffefbdfafec6be4c429
child 353628 5a67b0701200d2c31b58c8c560fdc80f218178b6
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersseth
bugs1293577
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1293577 - Part 2. Add mutex to MetadataDecodingTask to protect from decoding races. r=seth
image/IDecodingTask.cpp
image/IDecodingTask.h
--- a/image/IDecodingTask.cpp
+++ b/image/IDecodingTask.cpp
@@ -153,25 +153,28 @@ AnimationDecodingTask::ShouldPreferSyncR
 }
 
 
 ///////////////////////////////////////////////////////////////////////////////
 // MetadataDecodingTask implementation.
 ///////////////////////////////////////////////////////////////////////////////
 
 MetadataDecodingTask::MetadataDecodingTask(NotNull<Decoder*> aDecoder)
-  : mDecoder(aDecoder)
+  : mMutex("mozilla::image::MetadataDecodingTask")
+  , mDecoder(aDecoder)
 {
   MOZ_ASSERT(mDecoder->IsMetadataDecode(),
              "Use DecodingTask for non-metadata decodes");
 }
 
 void
 MetadataDecodingTask::Run()
 {
+  MutexAutoLock lock(mMutex);
+
   LexerResult result = mDecoder->Decode(WrapNotNull(this));
 
   if (result.is<TerminalState>()) {
     NotifyDecodeComplete(mDecoder->GetImage(), mDecoder);
     return;  // We're done.
   }
 
   if (result == LexerResult(Yield::NEED_MORE_DATA)) {
--- a/image/IDecodingTask.h
+++ b/image/IDecodingTask.h
@@ -108,16 +108,19 @@ public:
 
   // Metadata decodes run at the highest priority because they block layout and
   // page load.
   TaskPriority Priority() const override { return TaskPriority::eHigh; }
 
 private:
   virtual ~MetadataDecodingTask() { }
 
+  /// Mutex protecting access to mDecoder.
+  Mutex mMutex;
+
   NotNull<RefPtr<Decoder>> mDecoder;
 };
 
 
 /**
  * An IDecodingTask implementation for anonymous decoders - that is, decoders
  * with no associated Image object.
  */