Skip to content

Commit 17b1ada

Browse files
committed
Add extra comments around memory barriers in Actor runtime atomics logic
Radar-Id: rdar://problem/88093007
1 parent 054bae5 commit 17b1ada

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,9 @@ void DefaultActorImpl::enqueue(Job *job, JobPriority priority) {
11361136
}
11371137
}
11381138

1139+
// This needs to be a store release so that we also publish the contents of
1140+
// the new Job we are adding to the atomic job queue. Pairs with load
1141+
// acquire in drainOne.
11391142
if (_status().compare_exchange_weak(oldState, newState,
11401143
/* success */ std::memory_order_release,
11411144
/* failure */ std::memory_order_relaxed)) {
@@ -1176,6 +1179,7 @@ void DefaultActorImpl::enqueue(Job *job, JobPriority priority) {
11761179
Job * DefaultActorImpl::drainOne() {
11771180
SWIFT_TASK_DEBUG_LOG("Draining one job from default actor %p", this);
11781181

1182+
// Pairs with the store release in DefaultActorImpl::enqueue
11791183
auto oldState = _status().load(std::memory_order_acquire);
11801184

11811185
auto jobToPreprocessFrom = oldState.getFirstJob();
@@ -1389,6 +1393,8 @@ retry:;
13891393
SWIFT_TASK_DEBUG_LOG("Thread attempting to jump onto %p, as drainer = %d", this, asDrainer);
13901394
#endif
13911395

1396+
// Note: This doesn't have to be a load acquire because the jobQueue is part
1397+
// of the same atomic.
13921398
auto oldState = _status().load(std::memory_order_relaxed);
13931399
while (true) {
13941400

0 commit comments

Comments
 (0)