Bug 816640: nrappkit timers need to be threadsafe r=ekr
authorRandell Jesup <rjesup@jesup.org>
Fri, 14 Dec 2012 18:16:29 -0500
changeset 116136 0e0f68fef5c4
parent 116135 6b9550f406de
child 116137 a6ba8f732257
push id24043
push userryanvm@gmail.com
push dateSat, 15 Dec 2012 21:18:16 +0000
treeherdermozilla-central@c8a1314aa449 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersekr
bugs816640
milestone20.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 816640: nrappkit timers need to be threadsafe r=ekr
media/mtransport/nr_timer.cpp
--- a/media/mtransport/nr_timer.cpp
+++ b/media/mtransport/nr_timer.cpp
@@ -38,17 +38,18 @@ private:
   virtual ~nrappkitTimerCallback() {}
 
 protected:
   /* additional members */
   NR_async_cb cb_;
   void *cb_arg_;
 };
 
-NS_IMPL_ISUPPORTS1(nrappkitTimerCallback, nsITimerCallback)
+// We're going to release ourself in the callback, so we need to be threadsafe
+NS_IMPL_THREADSAFE_ISUPPORTS1(nrappkitTimerCallback, nsITimerCallback)
 
 NS_IMETHODIMP nrappkitTimerCallback::Notify(nsITimer *timer) {
   r_log(LOG_GENERIC, LOG_DEBUG, "Timer callback fired");
   cb_(0, 0, cb_arg_);
 
   // Allow the timer to go away.
   timer->Release();
   return NS_OK;
@@ -74,16 +75,19 @@ int NR_async_timer_set(int timeout, NR_a
     return R_FAILED;
   }
 
   // We need an AddRef here to keep the timer alive, per the spec.
   timer->AddRef();
 
   if (handle)
     *handle = timer.get();
+  // Bug 818806: if we have no handle to the timer, we have no way to avoid
+  // it leaking (though not the callback object) if it never fires (or if
+  // we exit before it fires).
 
   return 0;
 }
 
 int NR_async_schedule(NR_async_cb cb, void *arg, char *func, int l) {
   return NR_async_timer_set(0, cb, arg, func, l, nullptr);
 }