Bug 1408693 - Add a lock to protect the sGPUCrashDataMap. r=jwwang
MozReview-Commit-ID: 7NDcoGMkKZ3
--- 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().