Bug 1318839 - Backport NS_DelayDispatchToCurrentThread from bug 1198381. r=lenzak800 a=gchang
☠☠ backed out by ae5275b8c53b ☠ ☠
authorAndrew Overholt <overholt@mozilla.com>
Fri, 09 Dec 2016 17:03:00 +0100
changeset 359119 9c5f97295bb524035ee20aed657c9001ccc6ca59
parent 359118 5aec4a29e94f25ddf86b24ddb3619e4b18d16dbc
child 359120 61d9cd6239b2a1eb6ec3fd16f0a4ffe57c6ecf73
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslenzak800, gchang
bugs1318839, 1198381
milestone51.0
Bug 1318839 - Backport NS_DelayDispatchToCurrentThread from bug 1198381. r=lenzak800 a=gchang
xpcom/glue/nsThreadUtils.cpp
xpcom/glue/nsThreadUtils.h
--- a/xpcom/glue/nsThreadUtils.cpp
+++ b/xpcom/glue/nsThreadUtils.cpp
@@ -218,16 +218,37 @@ NS_DelayedDispatchToCurrentThread(alread
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 #endif
 
   return thread->DelayedDispatch(event.forget(), aDelayMs);
 }
 
+nsresult
+NS_DelayedDispatchToCurrentThread(already_AddRefed<nsIRunnable>&& aEvent, uint32_t aDelayMs)
+{
+  nsCOMPtr<nsIRunnable> event(aEvent);
+#ifdef MOZILLA_INTERNAL_API
+  nsIThread* thread = NS_GetCurrentThread();
+  if (!thread) {
+    return NS_ERROR_UNEXPECTED;
+  }
+#else
+  nsresult rv;
+  nsCOMPtr<nsIThread> thread;
+  rv = NS_GetCurrentThread(getter_AddRefs(thread));
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+#endif
+
+  return thread->DelayedDispatch(event.forget(), aDelayMs);
+}
+
 #ifndef XPCOM_GLUE_AVOID_NSPR
 nsresult
 NS_ProcessPendingEvents(nsIThread* aThread, PRIntervalTime aTimeout)
 {
   nsresult rv = NS_OK;
 
 #ifdef MOZILLA_INTERNAL_API
   if (!aThread) {
--- a/xpcom/glue/nsThreadUtils.h
+++ b/xpcom/glue/nsThreadUtils.h
@@ -129,16 +129,20 @@ NS_DispatchToMainThread(nsIRunnable* aEv
 extern nsresult
 NS_DispatchToMainThread(already_AddRefed<nsIRunnable>&& aEvent,
                         uint32_t aDispatchFlags = NS_DISPATCH_NORMAL);
 
 extern nsresult
 NS_DelayedDispatchToCurrentThread(
   already_AddRefed<nsIRunnable>&& aEvent, uint32_t aDelayMs);
 
+extern nsresult
+NS_DelayedDispatchToCurrentThread(
+  already_AddRefed<nsIRunnable>&& aEvent, uint32_t aDelayMs);
+
 #ifndef XPCOM_GLUE_AVOID_NSPR
 /**
  * Process all pending events for the given thread before returning.  This
  * method simply calls ProcessNextEvent on the thread while HasPendingEvents
  * continues to return true and the time spent in NS_ProcessPendingEvents
  * does not exceed the given timeout value.
  *
  * @param aThread