Skip to content

Commit 995ce7f

Browse files
Applied review comments
1 parent 50681bf commit 995ce7f

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

include/swift/Basic/PriorityQueue.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,25 @@ class PriorityQueue {
8989

9090
/// Add a chain of nodes of mixed priorities to this queue.
9191
void enqueueContentsOf(Node otherHead) {
92+
if (!otherHead) return;
9293
Node runHead = otherHead;
93-
while (runHead) {
94-
int priorityIndex = NodeTraits::getPriorityIndex(runHead);
95-
94+
int priorityIndex = NodeTraits::getPriorityIndex(runHead);
95+
do {
9696
// Find run of jobs of the same priority
9797
Node runTail = runHead;
9898
Node next = NodeTraits::getNext(runTail);
99-
while (true) {
100-
if (!next) break;
101-
if (NodeTraits::getPriorityIndex(next) != priorityIndex) break;
99+
int nextRunPriorityIndex;
100+
while (next) {
101+
nextRunPriorityIndex = NodeTraits::getPriorityIndex(next);
102+
if (nextRunPriorityIndex != priorityIndex) break;
102103
runTail = next;
103104
next = NodeTraits::getNext(runTail);
104105
}
105106

106107
enqueueRun(priorityIndex, runHead, runTail);
107108
runHead = next;
108-
}
109+
priorityIndex = nextRunPriorityIndex;
110+
} while(runHead);
109111
}
110112

111113
Node dequeue() {

stdlib/public/Concurrency/Actor.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -969,8 +969,7 @@ class DefaultActorImplHeader : public HeapObject {
969969
// All the fields accessed under the actor's lock should be moved
970970
// to the end of the default-actor reservation to minimize false sharing.
971971
// The memory following the DefaultActorImpl object are the stored properties of
972-
// the actor, which are likely all isolated and therefore used only by the
973-
// current processing thread.
972+
// the actor, which are all accessed only by the current processing thread.
974973
class DefaultActorImplFooter {
975974
protected:
976975
#if !SWIFT_CONCURRENCY_ACTORS_AS_LOCKS
@@ -980,10 +979,11 @@ class DefaultActorImplFooter {
980979
// stored inside ActiveActorStatus. This list contains jobs in the LIFO order
981980
// regardless of their priorities.
982981
//
983-
// After that processing thread collects them and adds to the
984-
// `prioritisedJobs` while holding the actor lock.
982+
// When the processing thread sees new incoming jobs in
983+
// ActiveActorStatus, it reverses them and inserts them into
984+
// prioritizedJobs in the appropriate priority bucket.
985985
//
986-
PriorityQueue prioritisedJobs;
986+
PriorityQueue prioritizedJobs;
987987

988988
// As an optimisation, we handle unprioritized jobs when obtaining actor lock.
989989
// This flag is used to skip `processIncomingQueue()` on the iteration of the
@@ -1056,7 +1056,7 @@ class DefaultActorImpl
10561056
new (&this->drainLock) Mutex();
10571057
#else
10581058
_status().store(ActiveActorStatus(), std::memory_order_relaxed);
1059-
new (&this->prioritisedJobs) PriorityQueue();
1059+
new (&this->prioritizedJobs) PriorityQueue();
10601060
this->shouldProcessIncomingQueue = true;
10611061
#endif
10621062
SWIFT_TASK_DEBUG_LOG("Creating default actor %p", this);
@@ -1128,7 +1128,7 @@ class DefaultActorImpl
11281128
/// Called with actor lock held on current thread.
11291129
void processIncomingQueue();
11301130

1131-
/// Processes claimed incoming jobs into `prioritisedJobs`.
1131+
/// 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.
11341134
void handleUnprioritizedJobs(Job *head);
@@ -1426,7 +1426,7 @@ void DefaultActorImpl::handleUnprioritizedJobs(Job *head) {
14261426
reversed = head;
14271427
head = next;
14281428
}
1429-
prioritisedJobs.enqueueContentsOf(reversed);
1429+
prioritizedJobs.enqueueContentsOf(reversed);
14301430
shouldProcessIncomingQueue = false;
14311431
}
14321432

@@ -1435,8 +1435,8 @@ Job *DefaultActorImpl::drainOne() {
14351435
SWIFT_TASK_DEBUG_LOG("Draining one job from default actor %p", this);
14361436

14371437
processIncomingQueue();
1438-
traceJobQueue(this, prioritisedJobs.peek());
1439-
auto firstJob = prioritisedJobs.dequeue();
1438+
traceJobQueue(this, prioritizedJobs.peek());
1439+
auto firstJob = prioritizedJobs.dequeue();
14401440
if (!firstJob) {
14411441
SWIFT_TASK_DEBUG_LOG("No jobs to drain on actor %p", this);
14421442
} else {
@@ -1569,11 +1569,11 @@ void DefaultActorImpl::destroy() {
15691569
assert(!oldState.getFirstUnprioritisedJob() && "actor has queued jobs at destruction");
15701570

15711571
if (oldState.isIdle()) {
1572-
assert(prioritisedJobs.empty() && "actor has queued jobs at destruction");
1572+
assert(prioritizedJobs.empty() && "actor has queued jobs at destruction");
15731573
return;
15741574
}
15751575
assert(oldState.isRunning() && "actor scheduled but not running at destruction");
1576-
// In running state we cannot safely access prioritisedJobs to assert that it is empty.
1576+
// In running state we cannot safely access prioritizedJobs to assert that it is empty.
15771577
#endif
15781578
}
15791579

@@ -1667,7 +1667,7 @@ retry:;
16671667

16681668
assert(oldState.getMaxPriority() == JobPriority::Unspecified);
16691669
assert(!oldState.getFirstUnprioritisedJob());
1670-
// We cannot assert here that prioritisedJobs is empty,
1670+
// We cannot assert here that prioritizedJobs is empty,
16711671
// because lock is not held yet. Raise a flag to assert after getting the lock.
16721672
assertNoJobs = true;
16731673
}
@@ -1687,7 +1687,7 @@ retry:;
16871687
std::memory_order_relaxed)) {
16881688
_swift_tsan_acquire(this);
16891689
if (assertNoJobs) {
1690-
assert(prioritisedJobs.empty());
1690+
assert(prioritizedJobs.empty());
16911691
}
16921692
traceActorStateTransition(this, oldState, newState, distributedActorIsRemote);
16931693
handleUnprioritizedJobs(oldState.getFirstUnprioritisedJob());
@@ -1738,8 +1738,8 @@ bool DefaultActorImpl::unlock(bool forceUnlock)
17381738
}
17391739

17401740
auto newState = oldState;
1741-
// Lock is still held at this point, so it is safe to access prioritisedJobs
1742-
if (!prioritisedJobs.empty() || oldState.getFirstUnprioritisedJob()) {
1741+
// Lock is still held at this point, so it is safe to access prioritizedJobs
1742+
if (!prioritizedJobs.empty() || oldState.getFirstUnprioritisedJob()) {
17431743
// There is work left to do, don't unlock the actor
17441744
if (!forceUnlock) {
17451745
SWIFT_TASK_DEBUG_LOG("Unlock-ing actor %p failed", this);

0 commit comments

Comments
 (0)