Bug 1056356 - Allow calling NewRunnableMethod() with a const pointer to the callee object. r=froydnj
authorBotond Ballo <botond@mozilla.com>
Wed, 29 Jul 2015 19:51:36 -0400
changeset 288091 d22e3da3ebcf475d546986b6f348cf317984ce83
parent 288090 eeab332c767c30d0134d8c76d8b4ce6d17d7faaa
child 288092 27d20d1b6f9a0f0361b2ef60875366d08de6c617
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1056356
milestone42.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 1056356 - Allow calling NewRunnableMethod() with a const pointer to the callee object. r=froydnj
ipc/chromium/src/base/task.h
--- a/ipc/chromium/src/base/task.h
+++ b/ipc/chromium/src/base/task.h
@@ -262,16 +262,29 @@ struct RunnableMethodTraits {
   static void RetainCallee(T* obj) {
     obj->AddRef();
   }
   static void ReleaseCallee(T* obj) {
     obj->Release();
   }
 };
 
+// This allows using the NewRunnableMethod() functions with a const pointer
+// to the callee object. See the similar support in nsRefPtr for a rationale
+// of why this is reasonable.
+template <class T>
+struct RunnableMethodTraits<const T> {
+  static void RetainCallee(const T* obj) {
+    const_cast<T*>(obj)->AddRef();
+  }
+  static void ReleaseCallee(const  T* obj) {
+    const_cast<T*>(obj)->Release();
+  }
+};
+
 // RunnableMethod and RunnableFunction -----------------------------------------
 //
 // Runnable methods are a type of task that call a function on an object when
 // they are run. We implement both an object and a set of NewRunnableMethod and
 // NewRunnableFunction functions for convenience. These functions are
 // overloaded and will infer the template types, simplifying calling code.
 //
 // The template definitions all use the following names: