Skip to content

Commit acec3e4

Browse files
Revert "Revert some changes for cleaner diff"
This reverts commit d3a2530.
1 parent 995ce7f commit acec3e4

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,13 @@ class DefaultActorImpl
10851085
/// new priority
10861086
void enqueueStealer(Job *job, JobPriority priority);
10871087

1088-
/// Processes incoming jobs if needed and dequeues one job of the highest priority.
1089-
/// The calling thread must be holding the actor lock while calling this.
1088+
/// Dequeues one job from `prioritisedJobs`.
1089+
/// The calling thread must be holding the actor lock while calling this
10901090
Job *drainOne();
1091+
1092+
/// Atomically claims incoming jobs from ActiveActorStatus, and calls `handleUnprioritizedJobs()`.
1093+
/// Called with actor lock held on current thread.
1094+
void processIncomingQueue();
10911095
#endif
10921096

10931097
/// Check if the actor is actually a distributed *remote* actor.
@@ -1124,10 +1128,6 @@ class DefaultActorImpl
11241128
/// when actor gets a priority override and we schedule a stealer.
11251129
void scheduleActorProcessJob(JobPriority priority);
11261130

1127-
/// Atomically claims incoming jobs from ActiveActorStatus, and calls `handleUnprioritizedJobs()`.
1128-
/// Called with actor lock held on current thread.
1129-
void processIncomingQueue();
1130-
11311131
/// Processes claimed incoming jobs into `prioritizedJobs`.
11321132
/// Incoming jobs are of mixed priorities and in LIFO order.
11331133
/// Called with actor lock held on current thread.
@@ -1434,7 +1434,6 @@ void DefaultActorImpl::handleUnprioritizedJobs(Job *head) {
14341434
Job *DefaultActorImpl::drainOne() {
14351435
SWIFT_TASK_DEBUG_LOG("Draining one job from default actor %p", this);
14361436

1437-
processIncomingQueue();
14381437
traceJobQueue(this, prioritizedJobs.peek());
14391438
auto firstJob = prioritizedJobs.dequeue();
14401439
if (!firstJob) {
@@ -1499,39 +1498,40 @@ static void defaultActorDrain(DefaultActorImpl *actor) {
14991498
TaskExecutorRef::undefined());
15001499

15011500
while (true) {
1502-
if (shouldYieldThread()) {
1503-
currentActor->unlock(true);
1504-
break;
1505-
}
1506-
15071501
Job *job = currentActor->drainOne();
15081502
if (job == NULL) {
15091503
// No work left to do, try unlocking the actor. This may fail if there is
15101504
// work concurrently enqueued in which case, we'd try again in the loop
1511-
if (!currentActor->unlock(false)) {
1512-
continue;
1505+
if (currentActor->unlock(false)) {
1506+
break;
1507+
}
1508+
} else {
1509+
if (AsyncTask *task = dyn_cast<AsyncTask>(job)) {
1510+
auto taskExecutor = task->getPreferredTaskExecutor();
1511+
trackingInfo.setTaskExecutor(taskExecutor);
15131512
}
1514-
break;
1515-
}
15161513

1517-
if (AsyncTask *task = dyn_cast<AsyncTask>(job)) {
1518-
auto taskExecutor = task->getPreferredTaskExecutor();
1519-
trackingInfo.setTaskExecutor(taskExecutor);
1514+
// This thread is now going to follow the task on this actor. It may hop off
1515+
// the actor
1516+
runJobInEstablishedExecutorContext(job);
1517+
1518+
// We could have come back from the job on a generic executor and not as
1519+
// part of a default actor. If so, there is no more work left for us to do
1520+
// here.
1521+
auto currentExecutor = trackingInfo.getActiveExecutor();
1522+
if (!currentExecutor.isDefaultActor()) {
1523+
currentActor = nullptr;
1524+
break;
1525+
}
1526+
currentActor = asImpl(currentExecutor.getDefaultActor());
15201527
}
15211528

1522-
// This thread is now going to follow the task on this actor. It may hop off
1523-
// the actor
1524-
runJobInEstablishedExecutorContext(job);
1525-
1526-
// We could have come back from the job on a generic executor and not as
1527-
// part of a default actor. If so, there is no more work left for us to do
1528-
// here.
1529-
auto currentExecutor = trackingInfo.getActiveExecutor();
1530-
if (!currentExecutor.isDefaultActor()) {
1531-
currentActor = nullptr;
1529+
if (shouldYieldThread()) {
1530+
currentActor->unlock(true);
15321531
break;
15331532
}
1534-
currentActor = asImpl(currentExecutor.getDefaultActor());
1533+
1534+
currentActor->processIncomingQueue();
15351535
}
15361536

15371537
// Leave the tracking info.

0 commit comments

Comments
 (0)