mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 1435263 - Get rid of WorkerPrivateParent template - part 2 - mMainThreadObjectsForgotten, r=bkelly
This commit is contained in:
parent
6c62c6ebec
commit
5f3cee24f1
@ -1561,7 +1561,7 @@ WorkerPrivateParent<Derived>::WorkerPrivateParent(
|
||||
mWorkerName(aWorkerName),
|
||||
mLoadingWorkerScript(false), mParentWindowPausedDepth(0),
|
||||
mParentFrozen(false),
|
||||
mIsChromeWorker(aIsChromeWorker), mMainThreadObjectsForgotten(false),
|
||||
mIsChromeWorker(aIsChromeWorker),
|
||||
mIsSecureContext(false), mWorkerType(aWorkerType),
|
||||
mCreationTimeStamp(TimeStamp::Now()),
|
||||
mCreationTimeHighRes((double)PR_Now() / PR_USEC_PER_MSEC)
|
||||
@ -1630,14 +1630,11 @@ WorkerPrivateParent<Derived>::~WorkerPrivateParent()
|
||||
DropJSObjects(this);
|
||||
}
|
||||
|
||||
template <class Derived>
|
||||
void
|
||||
WorkerPrivateParent<Derived>::Traverse(nsCycleCollectionTraversalCallback& aCb)
|
||||
WorkerPrivate::Traverse(nsCycleCollectionTraversalCallback& aCb)
|
||||
{
|
||||
AssertIsOnParentThread();
|
||||
|
||||
WorkerPrivate* self = ParentAsWorkerPrivate();
|
||||
|
||||
// The WorkerPrivate::mParentEventTargetRef has a reference to the exposed
|
||||
// Worker object, which is really held by the worker thread. We traverse this
|
||||
// reference if and only if our busy count is zero and we have not released
|
||||
@ -1645,9 +1642,9 @@ WorkerPrivateParent<Derived>::Traverse(nsCycleCollectionTraversalCallback& aCb)
|
||||
// break cycles involving the Worker and begin shutting it down (which does
|
||||
// happen in unlink) but ensures that the WorkerPrivate won't be deleted
|
||||
// before we're done shutting down the thread.
|
||||
if (!self->mBusyCount && !mMainThreadObjectsForgotten) {
|
||||
if (!mBusyCount && !mMainThreadObjectsForgotten) {
|
||||
nsCycleCollectionTraversalCallback& cb = aCb;
|
||||
WorkerPrivateParent<Derived>* tmp = this;
|
||||
WorkerPrivate* tmp = this;
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParentEventTargetRef);
|
||||
}
|
||||
}
|
||||
@ -2125,7 +2122,9 @@ bool
|
||||
WorkerPrivateParent<Derived>::ProxyReleaseMainThreadObjects()
|
||||
{
|
||||
AssertIsOnParentThread();
|
||||
MOZ_ASSERT(!mMainThreadObjectsForgotten);
|
||||
|
||||
WorkerPrivate* self = ParentAsWorkerPrivate();
|
||||
MOZ_ASSERT(!self->mMainThreadObjectsForgotten);
|
||||
|
||||
nsCOMPtr<nsILoadGroup> loadGroupToCancel;
|
||||
// If we're not overriden, then do nothing here. Let the load group get
|
||||
@ -2137,7 +2136,7 @@ WorkerPrivateParent<Derived>::ProxyReleaseMainThreadObjects()
|
||||
bool result = mLoadInfo.ProxyReleaseMainThreadObjects(ParentAsWorkerPrivate(),
|
||||
loadGroupToCancel);
|
||||
|
||||
mMainThreadObjectsForgotten = true;
|
||||
self->mMainThreadObjectsForgotten = true;
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -2785,6 +2784,7 @@ WorkerPrivate::WorkerPrivate(WorkerPrivate* aParent,
|
||||
, mWorkerScriptExecutedSuccessfully(false)
|
||||
, mFetchHandlerWasAdded(false)
|
||||
, mOnLine(false)
|
||||
, mMainThreadObjectsForgotten(false)
|
||||
, mBusyCount(0)
|
||||
{
|
||||
if (aParent) {
|
||||
|
@ -156,7 +156,6 @@ private:
|
||||
uint32_t mParentWindowPausedDepth;
|
||||
bool mParentFrozen;
|
||||
bool mIsChromeWorker;
|
||||
bool mMainThreadObjectsForgotten;
|
||||
// mIsSecureContext is set once in our constructor; after that it can be read
|
||||
// from various threads. We could make this const if we were OK with setting
|
||||
// it in the initializer list via calling some function that takes all sorts
|
||||
@ -171,22 +170,6 @@ private:
|
||||
DOMHighResTimeStamp mCreationTimeHighRes;
|
||||
|
||||
protected:
|
||||
// The worker is owned by its thread, which is represented here. This is set
|
||||
// in Constructor() and emptied by WorkerFinishedRunnable, and conditionally
|
||||
// traversed by the cycle collector if the busy count is zero.
|
||||
//
|
||||
// There are 4 ways a worker can be terminated:
|
||||
// 1. GC/CC - When the worker is in idle state (busycount == 0), it allows to
|
||||
// traverse the 'hidden' mParentEventTargetRef pointer. This is the exposed
|
||||
// Worker webidl object. Doing this, CC will be able to detect a cycle and
|
||||
// Unlink is called. In Unlink, Worker calls Terminate().
|
||||
// 2. Worker::Terminate() is called - the shutdown procedure starts
|
||||
// immediately.
|
||||
// 3. WorkerScope::Close() is called - Similar to point 2.
|
||||
// 4. xpcom-shutdown notification - We call Kill().
|
||||
RefPtr<Worker> mParentEventTargetRef;
|
||||
RefPtr<WorkerPrivate> mSelfRef;
|
||||
|
||||
WorkerPrivateParent(WorkerPrivate* aParent,
|
||||
const nsAString& aScriptURL, bool aIsChromeWorker,
|
||||
WorkerType aWorkerType,
|
||||
@ -215,24 +198,12 @@ private:
|
||||
public:
|
||||
NS_INLINE_DECL_REFCOUNTING(WorkerPrivateParent)
|
||||
|
||||
void
|
||||
Traverse(nsCycleCollectionTraversalCallback& aCb);
|
||||
|
||||
void
|
||||
EnableDebugger();
|
||||
|
||||
void
|
||||
DisableDebugger();
|
||||
|
||||
void
|
||||
ClearSelfAndParentEventTargetRef()
|
||||
{
|
||||
AssertIsOnParentThread();
|
||||
MOZ_ASSERT(mSelfRef);
|
||||
mParentEventTargetRef = nullptr;
|
||||
mSelfRef = nullptr;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Dispatch(already_AddRefed<WorkerRunnable> aRunnable);
|
||||
|
||||
@ -847,6 +818,22 @@ class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate>
|
||||
NoTimer
|
||||
};
|
||||
|
||||
// The worker is owned by its thread, which is represented here. This is set
|
||||
// in Constructor() and emptied by WorkerFinishedRunnable, and conditionally
|
||||
// traversed by the cycle collector if the busy count is zero.
|
||||
//
|
||||
// There are 4 ways a worker can be terminated:
|
||||
// 1. GC/CC - When the worker is in idle state (busycount == 0), it allows to
|
||||
// traverse the 'hidden' mParentEventTargetRef pointer. This is the exposed
|
||||
// Worker webidl object. Doing this, CC will be able to detect a cycle and
|
||||
// Unlink is called. In Unlink, Worker calls Terminate().
|
||||
// 2. Worker::Terminate() is called - the shutdown procedure starts
|
||||
// immediately.
|
||||
// 3. WorkerScope::Close() is called - Similar to point 2.
|
||||
// 4. xpcom-shutdown notification - We call Kill().
|
||||
RefPtr<Worker> mParentEventTargetRef;
|
||||
RefPtr<WorkerPrivate> mSelfRef;
|
||||
|
||||
bool mDebuggerRegistered;
|
||||
WorkerDebugger* mDebugger;
|
||||
|
||||
@ -917,6 +904,7 @@ class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate>
|
||||
bool mWorkerScriptExecutedSuccessfully;
|
||||
bool mFetchHandlerWasAdded;
|
||||
bool mOnLine;
|
||||
bool mMainThreadObjectsForgotten;
|
||||
|
||||
// This is touched on parent thread only, but it can be read on a different
|
||||
// thread before crashing because hanging.
|
||||
@ -945,6 +933,18 @@ public:
|
||||
LoadGroupBehavior aLoadGroupBehavior, WorkerType aWorkerType,
|
||||
WorkerLoadInfo* aLoadInfo);
|
||||
|
||||
void
|
||||
Traverse(nsCycleCollectionTraversalCallback& aCb);
|
||||
|
||||
void
|
||||
ClearSelfAndParentEventTargetRef()
|
||||
{
|
||||
AssertIsOnParentThread();
|
||||
MOZ_ASSERT(mSelfRef);
|
||||
mParentEventTargetRef = nullptr;
|
||||
mSelfRef = nullptr;
|
||||
}
|
||||
|
||||
// The passed principal must be the Worker principal in case of a
|
||||
// ServiceWorker and the loading principal for any other type.
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user