Skip to content

Commit e13f0fa

Browse files
committed
Bug 1318226. P1 - preserve the order of regular tasks. r=bholley
MozReview-Commit-ID: FYjbJWYDyd0 --HG-- extra : rebase_source : 1baeeb8d4e5904094bd258893d5cb59ec9ac8944 extra : intermediate-source : 224087f24319d562484be55f3b97a21f9d50577b extra : source : b6e940be26be76ae7620037b93c98e42504ed979
1 parent 829c0b3 commit e13f0fa

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

xpcom/threads/TaskDispatcher.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,15 @@ class AutoTaskDispatcher : public TaskDispatcher
124124
already_AddRefed<nsIRunnable> aRunnable,
125125
AbstractThread::DispatchFailureHandling aFailureHandling) override
126126
{
127-
PerThreadTaskGroup& group = EnsureTaskGroup(aThread);
127+
// To preserve the event order, we need to append a new group if the last
128+
// group is not targeted for |aThread|.
129+
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1318226&mark=0-3#c0
130+
// for the details of the issue.
131+
if (mTaskGroups.Length() == 0 || mTaskGroups.LastElement()->mThread != aThread) {
132+
mTaskGroups.AppendElement(new PerThreadTaskGroup(aThread));
133+
}
134+
135+
PerThreadTaskGroup& group = *mTaskGroups.LastElement();
128136
group.mRegularTasks.AppendElement(aRunnable);
129137

130138
// The task group needs to assert dispatch success if any of the runnables
@@ -142,11 +150,11 @@ class AutoTaskDispatcher : public TaskDispatcher
142150

143151
void DispatchTasksFor(AbstractThread* aThread) override
144152
{
153+
// Dispatch all groups that match |aThread|.
145154
for (size_t i = 0; i < mTaskGroups.Length(); ++i) {
146155
if (mTaskGroups[i]->mThread == aThread) {
147156
DispatchTaskGroup(Move(mTaskGroups[i]));
148-
mTaskGroups.RemoveElementAt(i);
149-
return;
157+
mTaskGroups.RemoveElementAt(i--);
150158
}
151159
}
152160
}

0 commit comments

Comments
 (0)