Skip to content

Commit 90bf377

Browse files
committed
NFC: Rename isLocked to isStatusRecordLocked to more explicitly
distinguish from the drain lock of the task that will be added next Radar-Id: rdar://problem/76127624
1 parent c8ab423 commit 90bf377

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

stdlib/public/Concurrency/TaskPrivate.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ class alignas(sizeof(void*) * 2) ActiveTaskStatus {
176176
IsCancelled = 0x100,
177177

178178
/// Whether the task status is "locked", meaning that further
179-
/// accesses need to wait on the task status record lock
180-
IsLocked = 0x200,
179+
/// accesses need to wait on the task status record lock. This is separate
180+
/// from the drain lock of the task.
181+
IsStatusRecordLocked = 0x200,
181182

182183
/// Whether the running priority has been escalated above the
183184
/// priority recorded in the Job header.
@@ -226,11 +227,11 @@ class alignas(sizeof(void*) * 2) ActiveTaskStatus {
226227
}
227228

228229
/// Is there an active lock on the cancellation information?
229-
bool isLocked() const { return Flags & IsLocked; }
230+
bool isStatusRecordLocked() const { return Flags & IsStatusRecordLocked; }
230231
ActiveTaskStatus withLockingRecord(TaskStatusRecord *lockRecord) const {
231-
assert(!isLocked());
232+
assert(!isStatusRecordLocked());
232233
assert(lockRecord->Parent == Record);
233-
return ActiveTaskStatus(lockRecord, Flags | IsLocked);
234+
return ActiveTaskStatus(lockRecord, Flags | IsStatusRecordLocked);
234235
}
235236

236237
JobPriority getStoredPriority() const {
@@ -389,7 +390,7 @@ inline void AsyncTask::flagAsRunning() {
389390
auto oldStatus = _private().Status.load(std::memory_order_relaxed);
390391
while (true) {
391392
assert(!oldStatus.isRunning());
392-
if (oldStatus.isLocked()) {
393+
if (oldStatus.isStatusRecordLocked()) {
393394
flagAsRunning_slow();
394395
adoptTaskVoucher(this);
395396
swift_task_enterThreadLocalContext(
@@ -421,7 +422,7 @@ inline void AsyncTask::flagAsSuspended() {
421422
auto oldStatus = _private().Status.load(std::memory_order_relaxed);
422423
while (true) {
423424
assert(oldStatus.isRunning());
424-
if (oldStatus.isLocked()) {
425+
if (oldStatus.isStatusRecordLocked()) {
425426
flagAsSuspended_slow();
426427
swift_task_exitThreadLocalContext(
427428
(char *)&_private().ExclusivityAccessSet[0]);

stdlib/public/Concurrency/TaskStatus.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class StatusRecordLockRecord :
8383
/// Wait for a task's status record lock to be unlocked.
8484
///
8585
/// When this function returns, `oldStatus` will have been updated
86-
/// to the last value read and `isLocked()` will be false.
86+
/// to the last value read and `isStatusRecordLocked()` will be false.
8787
/// Of course, another thread may still be concurrently trying
8888
/// to acquire the record lock.
8989
static void waitForStatusRecordUnlock(AsyncTask *task,
@@ -92,12 +92,12 @@ static void waitForStatusRecordUnlock(AsyncTask *task,
9292
StatusRecordLockRecord::Waiter waiter(StatusRecordLockLock);
9393

9494
while (true) {
95-
assert(oldStatus.isLocked());
95+
assert(oldStatus.isStatusRecordLocked());
9696

9797
bool waited = waiter.tryReloadAndWait([&]() -> StatusRecordLockRecord* {
9898
// Check that oldStatus is still correct.
9999
oldStatus = task->_private().Status.load(std::memory_order_acquire);
100-
if (!oldStatus.isLocked())
100+
if (!oldStatus.isStatusRecordLocked())
101101
return nullptr;
102102

103103
// The innermost entry should be a record lock record; wait
@@ -110,7 +110,7 @@ static void waitForStatusRecordUnlock(AsyncTask *task,
110110

111111
// Reload the status before trying to relock.
112112
oldStatus = task->_private().Status.load(std::memory_order_acquire);
113-
if (!oldStatus.isLocked())
113+
if (!oldStatus.isStatusRecordLocked())
114114
return;
115115
}
116116
}
@@ -171,7 +171,7 @@ static bool withStatusRecordLock(AsyncTask *task,
171171
return false;
172172

173173
// If the old info says we're locked, wait for the lock to clear.
174-
if (status.isLocked()) {
174+
if (status.isStatusRecordLocked()) {
175175
waitForStatusRecordUnlock(task, status);
176176
continue;
177177
}
@@ -231,7 +231,7 @@ static bool withStatusRecordLock(AsyncTask *task,
231231
// task will see, we need to do so in some other way, probably via
232232
// atomic objects in the task status records. Because of this, we can
233233
// actually unpublish the lock with a relaxed store.
234-
assert(!status.isLocked());
234+
assert(!status.isStatusRecordLocked());
235235
status.traceStatusChanged(task);
236236
task->_private().Status.store(status,
237237
/*success*/ std::memory_order_relaxed);
@@ -271,7 +271,7 @@ bool swift::addStatusRecord(
271271

272272
while (true) {
273273
// Wait for any active lock to be released.
274-
if (oldStatus.isLocked())
274+
if (oldStatus.isStatusRecordLocked())
275275
waitForStatusRecordUnlock(task, oldStatus);
276276

277277
// Reset the parent of the new record.
@@ -309,7 +309,7 @@ bool swift::removeStatusRecord(TaskStatusRecord *record) {
309309

310310
while (true) {
311311
// Wait for any active lock to be released.
312-
if (oldStatus.isLocked())
312+
if (oldStatus.isStatusRecordLocked())
313313
waitForStatusRecordUnlock(task, oldStatus);
314314

315315
// If the record is the innermost record, try to just pop it off.
@@ -653,9 +653,9 @@ static NearestTaskDeadline swift_task_getNearestDeadlineImpl(AsyncTask *task) {
653653

654654
// If it's locked, wait for the lock; we can't safely step through
655655
// the RecordLockStatusRecord on a different thread.
656-
if (oldStatus.isLocked()) {
656+
if (oldStatus.isStatusRecordLocked()) {
657657
waitForStatusRecordUnlock(task, oldStatus);
658-
assert(!oldStatus.isLocked());
658+
assert(!oldStatus.isStatusRecordLocked());
659659
}
660660

661661
// Walk all the records looking for deadlines.

0 commit comments

Comments
 (0)