Skip to content

Commit bb16d73

Browse files
committed
[Concurrency] add TaskLocal::Item:iisParentPointer for cleaner API
1 parent cd0708b commit bb16d73

File tree

4 files changed

+13
-64
lines changed

4 files changed

+13
-64
lines changed

Diff for: include/swift/ABI/TaskLocal.h

+9
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ class TaskLocal {
6969
// Trailing storage for the value itself. The storage will be
7070
// uninitialized or contain an instance of \c valueType.
7171

72+
/// Returns true if this item is a 'parent pointer'.
73+
///
74+
/// A parent pointer is special kind of `Item` is created when pointing at
75+
/// the parent storage, forming a chain of task local items spanning multiple
76+
/// tasks.
77+
bool isParentPointer() const {
78+
return !valueType;
79+
}
80+
7281
protected:
7382
explicit Item()
7483
: next(0),

Diff for: stdlib/public/Concurrency/TaskLocal.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ void TaskLocal::Item::copyTo(AsyncTask *target) {
224224
// 'parent' pointers are signified by null valueType.
225225
// We must not copy parent pointers, but rather perform a deep copy of all values,
226226
// as such, we skip parent pointers here entirely.
227-
if (!valueType)
227+
if (isParentPointer())
228228
return;
229229

230230
auto item = Item::createLink(target, key, valueType);

Diff for: test/Concurrency/Runtime/async_task_locals_copy_to_async.swift

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ func test_unstructured_noValues_childTasks() async {
139139
try await downloadImage(from: "")
140140
}
141141
}
142+
143+
// these child tasks have a parent pointer in their task local storage.
144+
// we must not copy it when performing the copyTo for a new unstructured task.
142145
async let one = work()
143146
async let two = work()
144147
async let three = work()

Diff for: test/Concurrency/Runtime/async_task_locals_repro.swift

-63
This file was deleted.

0 commit comments

Comments
 (0)