From 48e491736c8cec5cab836860a21dc0a52e5693f7 Mon Sep 17 00:00:00 2001 From: Chris H-C Date: Wed, 31 Aug 2016 13:31:30 -0400 Subject: [PATCH] bug 1218576 - Ensure IPCTimer is on the main thread. r?froydnj nsTimer fires on the thread that created the timer. An nsTimer instance should only be manipulated on its target thread (it isn't threadsafe). IPC using PContent must be on the main thread. Thus, everything to do with the gIPCTimer must be on the main thread. This also takes care of bug 1299312. MozReview-Commit-ID: IcVRYsoX2R9 --- toolkit/components/telemetry/TelemetryHistogram.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/toolkit/components/telemetry/TelemetryHistogram.cpp b/toolkit/components/telemetry/TelemetryHistogram.cpp index 144d875..06a49a8 100644 --- a/toolkit/components/telemetry/TelemetryHistogram.cpp +++ b/toolkit/components/telemetry/TelemetryHistogram.cpp @@ -1268,8 +1268,9 @@ internal_SetHistogramRecordingEnabled(mozilla::Telemetry::ID aID, bool aEnabled) MOZ_ASSERT(false, "Telemetry::SetHistogramRecordingEnabled(...) id not found"); } -void internal_armIPCTimer() +void internal_armIPCTimerMainThread() { + MOZ_ASSERT(NS_IsMainThread()); if (gIPCTimerArmed) { return; } @@ -1284,6 +1285,15 @@ void internal_armIPCTimer() } } +void internal_armIPCTimer() +{ + if (NS_IsMainThread()) { + internal_armIPCTimerMainThread(); + } else { + NS_DispatchToMainThread(NS_NewRunnableFunction(&internal_armIPCTimerMainThread)); + } +} + bool internal_RemoteAccumulate(mozilla::Telemetry::ID aId, uint32_t aSample) { @@ -2626,11 +2636,11 @@ TelemetryHistogram::GetHistogramSizesofIncludingThis(mozilla::MallocSizeOf // To ensure we don't loop IPCTimerFired->AccumulateChild->arm timer, we don't // unset gIPCTimerArmed until the IPC completes // -// This function may be re-entered. The shared datastructures gAccumulations and -// gKeyedAccumulations are guarded by the lock. +// This function must be called on the main thread, otherwise IPC will fail. void TelemetryHistogram::IPCTimerFired(nsITimer* aTimer, void* aClosure) { + MOZ_ASSERT(NS_IsMainThread()); nsTArray accumulationsToSend; nsTArray keyedAccumulationsToSend; { -- 2.7.4.windows.1