Skip to content

Commit 5ab2c36

Browse files
Revert "Process incoming queue when obtaining non-drainer lock as well"
This reverts commit 74d25eb.
1 parent acec3e4 commit 5ab2c36

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -984,13 +984,6 @@ class DefaultActorImplFooter {
984984
// prioritizedJobs in the appropriate priority bucket.
985985
//
986986
PriorityQueue prioritizedJobs;
987-
988-
// As an optimisation, we handle unprioritized jobs when obtaining actor lock.
989-
// This flag is used to skip `processIncomingQueue()` on the iteration of the
990-
// drainer loop right after taking the lock.
991-
// This applies both to obtaining lock when entering the drainer loop, and
992-
// when assuming thread for switching to a new actor.
993-
bool shouldProcessIncomingQueue;
994987
#endif
995988
};
996989

@@ -1057,7 +1050,6 @@ class DefaultActorImpl
10571050
#else
10581051
_status().store(ActiveActorStatus(), std::memory_order_relaxed);
10591052
new (&this->prioritizedJobs) PriorityQueue();
1060-
this->shouldProcessIncomingQueue = true;
10611053
#endif
10621054
SWIFT_TASK_DEBUG_LOG("Creating default actor %p", this);
10631055
concurrency::trace::actor_create(this);
@@ -1374,14 +1366,10 @@ void DefaultActorImpl::enqueueStealer(Job *job, JobPriority priority) {
13741366
#endif
13751367
}
13761368
}
1369+
13771370
}
13781371

13791372
void DefaultActorImpl::processIncomingQueue() {
1380-
if (!shouldProcessIncomingQueue) {
1381-
SWIFT_TASK_DEBUG_LOG("Skip processing incoming queue of default actor %p", this);
1382-
return;
1383-
}
1384-
13851373
// Pairs with the store release in DefaultActorImpl::enqueue
13861374
bool distributedActorIsRemote = swift_distributed_actor_is_remote(this);
13871375
auto oldState = _status().load(SWIFT_MEMORY_ORDER_CONSUME);
@@ -1427,7 +1415,6 @@ void DefaultActorImpl::handleUnprioritizedJobs(Job *head) {
14271415
head = next;
14281416
}
14291417
prioritizedJobs.enqueueContentsOf(reversed);
1430-
shouldProcessIncomingQueue = false;
14311418
}
14321419

14331420
// Called with actor lock held on current thread
@@ -1442,7 +1429,6 @@ Job *DefaultActorImpl::drainOne() {
14421429
SWIFT_TASK_DEBUG_LOG("Drained first job %p from actor %p", firstJob, this);
14431430
concurrency::trace::actor_dequeue(this, firstJob);
14441431
}
1445-
shouldProcessIncomingQueue = true;
14461432
return firstJob;
14471433
}
14481434

@@ -1677,9 +1663,11 @@ retry:;
16771663
auto newState = oldState.withRunning();
16781664
newState = newState.withoutEscalatedPriority();
16791665

1680-
// Claim incoming jobs when obtaining lock, to save one
1666+
// Claim incoming jobs when obtaining lock as a drainer, to save one
16811667
// round of atomic load and compare-exchange.
1682-
newState = newState.withFirstUnprioritisedJob(nullptr);
1668+
if (asDrainer) {
1669+
newState = newState.withFirstUnprioritisedJob(nullptr);
1670+
}
16831671

16841672
// This needs an acquire since we are taking a lock
16851673
if (_status().compare_exchange_weak(oldState, newState,
@@ -1690,7 +1678,9 @@ retry:;
16901678
assert(prioritizedJobs.empty());
16911679
}
16921680
traceActorStateTransition(this, oldState, newState, distributedActorIsRemote);
1693-
handleUnprioritizedJobs(oldState.getFirstUnprioritisedJob());
1681+
if (asDrainer) {
1682+
handleUnprioritizedJobs(oldState.getFirstUnprioritisedJob());
1683+
}
16941684
return true;
16951685
}
16961686
}

0 commit comments

Comments
 (0)