Bug 968016 - Implement nsThreadPool::IsOnCurrentThread() to return true when the current thread is in the thread pool. r=bsmedberg
authorChris Pearce <cpearce@mozilla.com>
Tue, 18 Feb 2014 11:53:52 +1300
changeset 169508 d71ac8b9f7ded0261113a9e078d39a296e23d33b
parent 169507 406b7fde02e24c786ebe70f6019a88a7e30b3ef9
child 169509 7102981f5c7208806bac2d697600c173fe3a6ce1
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersbsmedberg
bugs968016
milestone30.0a1
Bug 968016 - Implement nsThreadPool::IsOnCurrentThread() to return true when the current thread is in the thread pool. r=bsmedberg This is so that we can assert that media decode threads are in the decode thread pool.
xpcom/threads/nsThreadPool.cpp
--- a/xpcom/threads/nsThreadPool.cpp
+++ b/xpcom/threads/nsThreadPool.cpp
@@ -246,20 +246,24 @@ nsThreadPool::Dispatch(nsIRunnable *even
     PutEvent(event);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsThreadPool::IsOnCurrentThread(bool *result)
 {
-  // No one should be calling this method.  If this assertion gets hit, then we
-  // need to think carefully about what this method should be returning.
-  NS_NOTREACHED("implement me");
-
+  ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
+  nsIThread* thread = NS_GetCurrentThread();
+  for (uint32_t i = 0; i < mThreads.Count(); ++i) {
+    if (mThreads[i] == thread) {
+      *result = true;
+      return NS_OK;
+    }
+  }
   *result = false;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsThreadPool::Shutdown()
 {
   nsCOMArray<nsIThread> threads;