author | Olli Pettay <Olli.Pettay@helsinki.fi> |
Mon, 29 May 2017 17:04:36 +0300 | |
changeset 361093 | 4381d9011522dd86fd0aefdfb15c65f7ea9c9227 |
parent 361092 | eb0bcb60da8e5f2a918f41cdf49134e9799b5c54 |
child 361094 | adc68cbe1295500e348dd3ff8e6737f7b77006b0 |
push id | 90787 |
push user | opettay@mozilla.com |
push date | Mon, 29 May 2017 14:56:10 +0000 |
treeherder | mozilla-inbound@4381d9011522 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | bkelly |
bugs | 1368358 |
milestone | 55.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
|
--- a/xpcom/threads/ThrottledEventQueue.cpp +++ b/xpcom/threads/ThrottledEventQueue.cpp @@ -91,29 +91,25 @@ class ThrottledEventQueue::Inner final : nsEventQueue mEventQueue; // written on main thread, read on any thread nsCOMPtr<nsIEventTarget> mBaseTarget; // any thread, protected by mutex nsCOMPtr<nsIRunnable> mExecutor; - // any thread, atomic - Atomic<uint32_t> mExecutionDepth; - // any thread, protected by mutex bool mShutdownStarted; explicit Inner(nsIEventTarget* aBaseTarget) : mMutex("ThrottledEventQueue") , mIdleCondVar(mMutex, "ThrottledEventQueue:Idle") , mEventsAvailable(mMutex, "[ThrottledEventQueue::Inner.mEventsAvailable]") , mEventQueue(mEventsAvailable, nsEventQueue::eNormalQueue) , mBaseTarget(aBaseTarget) - , mExecutionDepth(0) , mShutdownStarted(false) { } ~Inner() { MOZ_ASSERT(!mExecutor); MOZ_ASSERT(mShutdownStarted); @@ -134,22 +130,17 @@ class ThrottledEventQueue::Inner final : MutexAutoLock lock(mMutex); // We only check the name of an executor runnable when we know there is something // in the queue, so this should never fail. MOZ_ALWAYS_TRUE(mEventQueue.PeekEvent(getter_AddRefs(event), lock)); } if (nsCOMPtr<nsINamed> named = do_QueryInterface(event)) { - // Increase mExecutionDepth here so that GetName is allowed to call - // IsOnCurrentThread on us and have it be true (in the case when we are on - // the right thread). - mExecutionDepth++; nsresult rv = named->GetName(aName); - mExecutionDepth--; return rv; } aName.AssignLiteral("non-nsINamed ThrottledEventQueue runnable"); return NS_OK; } void @@ -191,19 +182,17 @@ class ThrottledEventQueue::Inner final : shouldShutdown = mShutdownStarted; // Note, this breaks a ref cycle. mExecutor = nullptr; mIdleCondVar.NotifyAll(); } } // Execute the event now that we have unlocked. - ++mExecutionDepth; Unused << event->Run(); - --mExecutionDepth; // If shutdown was started and the queue is now empty we can now // finalize the shutdown. This is performed separately at the end // of the method in order to wait for the event to finish running. if (shouldShutdown) { MOZ_ASSERT(IsEmpty()); NS_DispatchToMainThread(NewRunnableMethod("ThrottledEventQueue::Inner::ShutdownComplete", this, &Inner::ShutdownComplete)); @@ -372,37 +361,17 @@ public: // The base target may implement this, but we don't. Always fail // to provide consistent behavior. return NS_ERROR_NOT_IMPLEMENTED; } nsresult IsOnCurrentThread(bool* aResult) { - // Any thread - - bool shutdownAndIdle = false; - { - MutexAutoLock lock(mMutex); - shutdownAndIdle = mShutdownStarted && mEventQueue.Count(lock) == 0; - } - - bool onBaseTarget = false; - nsresult rv = mBaseTarget->IsOnCurrentThread(&onBaseTarget); - if (NS_FAILED(rv)) { - return rv; - } - - // We consider the current stack on this event target if are on - // the base target and one of the following is true - // 1) We are currently running an event OR - // 2) We are both shutting down and the queue is idle - *aResult = onBaseTarget && (mExecutionDepth || shutdownAndIdle); - - return NS_OK; + return mBaseTarget->IsOnCurrentThread(aResult); } NS_DECL_THREADSAFE_ISUPPORTS }; NS_IMPL_ISUPPORTS(ThrottledEventQueue::Inner, nsIObserver); NS_IMPL_ISUPPORTS(ThrottledEventQueue, ThrottledEventQueue, nsIEventTarget);