Skip to content

Commit 4e20dd6

Browse files
author
Jean-Yves Avenard
committed
Bug 1646054 - P2. Always retain dispatch flags r=froydnj
When TaskQueue was first conceived; it was only used with AbstractThreads and with tail dispatch. By default, AbstractThread::Dispatch dropped the flags , as it was dispatching all tasks via the tail dispatcher. It was an oversight, there's no use-case where we wouldn't want the dispatch flags to be carried forward. It also simplifies the code and TaskQueue's use. Depends on D80351 Differential Revision: https://phabricator.services.mozilla.com/D80352
1 parent ea34205 commit 4e20dd6

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

xpcom/threads/TaskQueue.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,17 @@
1111
namespace mozilla {
1212

1313
TaskQueue::TaskQueue(already_AddRefed<nsIEventTarget> aTarget,
14-
const char* aName, bool aRequireTailDispatch,
15-
bool aRetainFlags)
14+
const char* aName, bool aRequireTailDispatch)
1615
: AbstractThread(aRequireTailDispatch),
1716
mTarget(aTarget),
1817
mQueueMonitor("TaskQueue::Queue"),
1918
mTailDispatcher(nullptr),
20-
mShouldRetainFlags(aRetainFlags),
2119
mIsRunning(false),
2220
mIsShutdown(false),
2321
mName(aName) {}
2422

2523
TaskQueue::TaskQueue(already_AddRefed<nsIEventTarget> aTarget,
26-
bool aSupportsTailDispatch, bool aRetainFlags)
24+
bool aSupportsTailDispatch)
2725
: TaskQueue(std::move(aTarget), "Unnamed", aSupportsTailDispatch) {}
2826

2927
TaskQueue::~TaskQueue() {
@@ -57,11 +55,8 @@ nsresult TaskQueue::DispatchLocked(nsCOMPtr<nsIRunnable>& aRunnable,
5755
return currentThread->TailDispatcher().AddTask(this, aRunnable.forget());
5856
}
5957

60-
// If the task queue cares about individual flags, retain them in the struct.
61-
uint32_t retainFlags = mShouldRetainFlags ? aFlags : 0;
62-
6358
LogRunnable::LogDispatch(aRunnable);
64-
mTasks.push({std::move(aRunnable), retainFlags});
59+
mTasks.push({std::move(aRunnable), aFlags});
6560

6661
if (mIsRunning) {
6762
return NS_OK;

xpcom/threads/TaskQueue.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,10 @@ class TaskQueue : public AbstractThread, public nsIDirectTaskDispatcher {
5353

5454
public:
5555
explicit TaskQueue(already_AddRefed<nsIEventTarget> aTarget,
56-
bool aSupportsTailDispatch = false,
57-
bool aRetainFlags = false);
56+
bool aSupportsTailDispatch = false);
5857

5958
TaskQueue(already_AddRefed<nsIEventTarget> aTarget, const char* aName,
60-
bool aSupportsTailDispatch = false, bool aRetainFlags = false);
59+
bool aSupportsTailDispatch = false);
6160

6261
NS_DECL_ISUPPORTS_INHERITED
6362
NS_DECL_NSIDIRECTTASKDISPATCHER
@@ -196,11 +195,6 @@ class TaskQueue : public AbstractThread, public nsIDirectTaskDispatcher {
196195

197196
TaskDispatcher* mTailDispatcher;
198197

199-
// TaskQueues should specify if they want all tasks to dispatch with their
200-
// original flags included, which means the flags will be retained in the
201-
// TaskStruct.
202-
bool mShouldRetainFlags;
203-
204198
// True if we've dispatched an event to the target to execute events from
205199
// the queue.
206200
bool mIsRunning;

xpcom/threads/nsThreadManager.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ already_AddRefed<nsISerialEventTarget>
184184
BackgroundEventTarget::CreateBackgroundTaskQueue(const char* aName) {
185185
MutexAutoLock lock(mMutex);
186186

187-
RefPtr<TaskQueue> queue = new TaskQueue(do_AddRef(this), aName,
188-
/*aSupportsTailDispatch=*/false,
189-
/*aRetainFlags=*/true);
187+
RefPtr<TaskQueue> queue = new TaskQueue(do_AddRef(this), aName);
190188
mTaskQueues.AppendElement(queue);
191189

192190
return queue.forget();

0 commit comments

Comments
 (0)