Bug 1408693 - Add a lock to protect the sGPUCrashDataMap. r=jwwang draft
authorbechen@mozilla.com <bechen@mozilla.com>
Mon, 16 Oct 2017 14:03:04 +0800
changeset 680705 206af0de83a1fb4fb5258202a25de8484a9e2bef
parent 675561 10ca1d0023d72a15fff4dfd968c44697800da521
child 683142 51c328d0b87b977aa2f2fefbc7ded150501985b2
push id84593
push userbmo:bechen@mozilla.com
push dateMon, 16 Oct 2017 06:06:33 +0000
reviewersjwwang
bugs1408693
milestone58.0a1
Bug 1408693 - Add a lock to protect the sGPUCrashDataMap. r=jwwang MozReview-Commit-ID: 7NDcoGMkKZ3
dom/media/MediaFormatReader.cpp
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -86,50 +86,54 @@ public:
                      MediaDataDecoderID aMediaDataDecoderID,
                      const TimeStamp& aGPUCrashTime,
                      const TimeStamp& aErrorNotifiedTime)
   {
     MOZ_ASSERT(aMediaDecoderOwnerID);
     MOZ_ASSERT(aMediaDataDecoderID);
     MOZ_ASSERT(!aGPUCrashTime.IsNull());
     MOZ_ASSERT(!aErrorNotifiedTime.IsNull());
+    StaticMutexAutoLock lock(sGPUCrashMapMutex);
     auto it = sGPUCrashDataMap.find(aMediaDecoderOwnerID);
     if (it == sGPUCrashDataMap.end()) {
       sGPUCrashDataMap.insert(std::make_pair(aMediaDecoderOwnerID,
                                              GPUCrashData(aMediaDataDecoderID,
                                                           aGPUCrashTime,
                                                           aErrorNotifiedTime)));
     }
   }
 
   static void
   ReportTelemetry(MediaDecoderOwnerID aMediaDecoderOwnerID,
                   MediaDataDecoderID aMediaDataDecoderID)
   {
     MOZ_ASSERT(aMediaDecoderOwnerID);
     MOZ_ASSERT(aMediaDataDecoderID);
+    StaticMutexAutoLock lock(sGPUCrashMapMutex);
     auto it = sGPUCrashDataMap.find(aMediaDecoderOwnerID);
     if (it != sGPUCrashDataMap.end() &&
         it->second.mMediaDataDecoderID != aMediaDataDecoderID) {
       Telemetry::AccumulateTimeDelta(
         Telemetry::VIDEO_HW_DECODER_CRASH_RECOVERY_TIME_SINCE_GPU_CRASHED_MS,
         it->second.mGPUCrashTime);
       Telemetry::AccumulateTimeDelta(
         Telemetry::VIDEO_HW_DECODER_CRASH_RECOVERY_TIME_SINCE_MFR_NOTIFIED_MS,
         it->second.mErrorNotifiedTime);
       sGPUCrashDataMap.erase(aMediaDecoderOwnerID);
     }
   }
 
 private:
   static std::map<MediaDecoderOwnerID, GPUCrashData> sGPUCrashDataMap;
+  static StaticMutex sGPUCrashMapMutex;
 };
 
 std::map<MediaDecoderOwnerID, GPUProcessCrashTelemetryLogger::GPUCrashData>
 GPUProcessCrashTelemetryLogger::sGPUCrashDataMap;
+StaticMutex GPUProcessCrashTelemetryLogger::sGPUCrashMapMutex;
 
 /**
  * This is a singleton which controls the number of decoders that can be
  * created concurrently. Before calling PDMFactory::CreateDecoder(), Alloc()
  * must be called to get a token object as a permission to create a decoder.
  * The token should stay alive until Shutdown() is called on the decoder.
  * The destructor of the token will restore the decoder count so it is available
  * for next calls of Alloc().