Backed out 3 changesets (bug 1660555) on request from evilpie

Backed out changeset 973fbed4566f (bug 1660555)
Backed out changeset 4e42fc2c7ff3 (bug 1660555)
Backed out changeset 86e154074372 (bug 1660555)
This commit is contained in:
Sebastian Hengst 2021-04-29 16:55:15 +02:00
parent e0a50323b4
commit 1df9c58475

View File

@ -108,12 +108,8 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(AbortSignalMainThread)
class AbortSignalProxy;
// An AbortFollower that follows an AbortSignal on a worker thread in order to
// propagate signaling abort back to the main thread's AbortSignal.
//
// This class is separate from AbortSignalProxy below so that its refcount is
// manipulated only on the worker thread.
class WorkerSignalFollower final : public AbortFollower {
public:
// This runnable propagates changes from the AbortSignalImpl on workers to the
// AbortSignalImpl on main-thread.
class AbortSignalProxyRunnable final : public Runnable {
@ -131,26 +127,10 @@ class WorkerSignalFollower final : public AbortFollower {
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(WorkerSignalFollower)
WorkerSignalFollower(AbortSignalProxy* aProxy, AbortSignalImpl* aSignalImpl)
: AbortFollower(), mProxy(aProxy) {
MOZ_ASSERT(!NS_IsMainThread());
// Follow the worker thread's signal.
Follow(aSignalImpl);
}
void RunAbortAlgorithm() override;
void Shutdown() {
MOZ_ASSERT(!NS_IsMainThread());
Unfollow();
mProxy = nullptr;
}
void RunAbortAlgorithm() override {}
private:
~WorkerSignalFollower() = default;
RefPtr<AbortSignalProxy> mProxy;
};
NS_IMPL_CYCLE_COLLECTION_CLASS(WorkerSignalFollower)
@ -160,7 +140,6 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(WorkerSignalFollower)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(WorkerSignalFollower)
AbortFollower::Unlink(static_cast<AbortFollower*>(tmp));
tmp->mProxy = nullptr;
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(WorkerSignalFollower)
@ -173,18 +152,7 @@ NS_INTERFACE_MAP_END
// This class orchestrates the proxying of AbortSignal operations between the
// main thread and a worker thread.
class AbortSignalProxy final {
// An AbortFollower, created/accessed/destroyed only on the worker thread,
// that follows the worker-thread AbortSignal and propagates signaling abort
// back to the main thread.
//
// mWorkerSignalFollower maintains a cyclic pointer back at this, that is
// broken by this->Shutdown() performed on the worker thread. That call is
// either performed by WeakWorkerRef if its worker is dropped on the floor, or
// at end of the worker fetch response (see
// WorkerFetchResponseEndBase::WorkerRunInternal).
RefPtr<WorkerSignalFollower> mWorkerSignalFollower;
class AbortSignalProxy final : public AbortFollower {
// This is created and released on the main-thread.
RefPtr<AbortSignalImpl> mSignalImplMainThread;
@ -198,7 +166,7 @@ class AbortSignalProxy final {
const bool mAborted;
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AbortSignalProxy)
NS_DECL_THREADSAFE_ISUPPORTS
AbortSignalProxy(AbortSignalImpl* aSignalImpl,
nsIEventTarget* aMainThreadEventTarget)
@ -206,10 +174,12 @@ class AbortSignalProxy final {
mAborted(aSignalImpl->Aborted()) {
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(mMainThreadEventTarget);
mWorkerSignalFollower = new WorkerSignalFollower(this, aSignalImpl);
Follow(aSignalImpl);
}
// AbortFollower
void RunAbortAlgorithm() override;
AbortSignalImpl* GetOrCreateSignalImplForMainThread() {
MOZ_ASSERT(NS_IsMainThread());
if (!mSignalImplMainThread) {
@ -220,27 +190,25 @@ class AbortSignalProxy final {
AbortSignalImpl* GetSignalImplForTargetThread() {
MOZ_ASSERT(!NS_IsMainThread());
return mWorkerSignalFollower->Signal();
return Signal();
}
nsIEventTarget* MainThreadEventTarget() { return mMainThreadEventTarget; }
void Shutdown() {
MOZ_ASSERT(!NS_IsMainThread());
mWorkerSignalFollower->Shutdown();
mWorkerSignalFollower = nullptr;
Unfollow();
}
private:
~AbortSignalProxy() {
MOZ_ASSERT(mWorkerSignalFollower == nullptr,
"Shutdown() should have been called, on the worker thread, to "
"release/free the worker thread's AbortSignal follower by now");
NS_ProxyRelease("AbortSignalProxy::mSignalImplMainThread",
mMainThreadEventTarget, mSignalImplMainThread.forget());
}
};
NS_IMPL_ISUPPORTS0(AbortSignalProxy)
NS_IMETHODIMP WorkerSignalFollower::AbortSignalProxyRunnable::Run() {
MOZ_ASSERT(NS_IsMainThread());
AbortSignalImpl* signalImpl = mProxy->GetOrCreateSignalImplForMainThread();
@ -248,12 +216,13 @@ NS_IMETHODIMP WorkerSignalFollower::AbortSignalProxyRunnable::Run() {
return NS_OK;
}
void WorkerSignalFollower::RunAbortAlgorithm() {
void AbortSignalProxy::RunAbortAlgorithm() {
MOZ_ASSERT(!NS_IsMainThread());
using AbortSignalProxyRunnable =
WorkerSignalFollower::AbortSignalProxyRunnable;
RefPtr<AbortSignalProxyRunnable> runnable =
new AbortSignalProxyRunnable(mProxy);
mProxy->MainThreadEventTarget()->Dispatch(runnable.forget(),
NS_DISPATCH_NORMAL);
new AbortSignalProxyRunnable(this);
MainThreadEventTarget()->Dispatch(runnable.forget(), NS_DISPATCH_NORMAL);
}
class WorkerFetchResolver final : public FetchDriverObserver {
@ -361,7 +330,6 @@ class WorkerFetchResolver final : public FetchDriverObserver {
if (mSignalProxy) {
mSignalProxy->Shutdown();
mSignalProxy = nullptr;
}
mWorkerRef = nullptr;