Bug 1408693 - Add a lock to protect the sGPUCrashDataMap. r=jwwang
authorbechen@mozilla.com <bechen@mozilla.com>
Mon, 16 Oct 2017 14:03:04 +0800
changeset 386511 615798b405f4994de32c6a9b0a464601accb0b0e
parent 386510 1dfddc19749e36b8cca7af133fe34498e57118bc
child 386512 2e36022d5347c2cea0c4d9847829a3ee516bb6e1
push id53434
push userryanvm@gmail.com
push dateTue, 17 Oct 2017 03:59:10 +0000
treeherderautoland@615798b405f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs1408693
milestone58.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 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().