bug 1304519 - Ensure we hold a lock before accumulating. r=gfritzsche
authorChris H-C <chutten@mozilla.com>
Tue, 04 Oct 2016 15:02:46 -0400
changeset 316689 ee7990c78dd9
parent 316688 971e37206edc
child 316690 471872efc401
push id20665
push usercbook@mozilla.com
push dateThu, 06 Oct 2016 10:29:09 +0000
treeherderfx-team@5ef613528dea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche
bugs1304519
milestone52.0a1
bug 1304519 - Ensure we hold a lock before accumulating. r=gfritzsche Lock calls to internal_Accumulate from functions that run without locks. This doesn't render TelemetryHistogram perfectly threadsafe. However, this does protect all accumulation sites. MozReview-Commit-ID: 16JUek8NiXI
toolkit/components/telemetry/TelemetryHistogram.cpp
--- a/toolkit/components/telemetry/TelemetryHistogram.cpp
+++ b/toolkit/components/telemetry/TelemetryHistogram.cpp
@@ -1547,17 +1547,20 @@ internal_JSHistogram_Add(JSContext *cx, 
     }
 
     if (!JS::ToUint32(cx, args[0], &value)) {
       JS_ReportErrorASCII(cx, "Failed to convert argument");
       return false;
     }
   }
 
-  internal_Accumulate(*h, value);
+  {
+    StaticMutexAutoLock locker(gTelemetryHistogramMutex);
+    internal_Accumulate(*h, value);
+  }
   return true;
 }
 
 bool
 internal_JSHistogram_Snapshot(JSContext *cx, unsigned argc, JS::Value *vp)
 {
   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
   JSObject *obj = JS_THIS_OBJECT(cx, vp);
@@ -1795,17 +1798,20 @@ internal_JSKeyedHistogram_Add(JSContext 
       return false;
     }
 
     if (!JS::ToInt32(cx, args[1], &value)) {
       return false;
     }
   }
 
-  internal_Accumulate(*keyed, NS_ConvertUTF16toUTF8(key), value);
+  {
+    StaticMutexAutoLock locker(gTelemetryHistogramMutex);
+    internal_Accumulate(*keyed, NS_ConvertUTF16toUTF8(key), value);
+  }
   return true;
 }
 
 bool
 internal_JSKeyedHistogram_Keys(JSContext *cx, unsigned argc, JS::Value *vp)
 {
   JSObject *obj = JS_THIS_OBJECT(cx, vp);
   if (!obj) {