@@ -149,39 +149,25 @@ static void swift_task_localValuePopImpl() {
149149
150150SWIFT_CC (swift)
151151static void swift_task_localsCopyToImpl(AsyncTask *target) {
152- TaskLocal::Storage *Local = nullptr ;
153-
154- if (AsyncTask *task = swift_task_getCurrent ()) {
155- Local = &task->_private ().Local ;
156- } else if (auto *storage = FallbackTaskLocalStorage::get ()) {
157- Local = storage;
158- } else {
159- // bail out, there are no values to copy
160- return ;
152+ if (auto Current = TaskLocal::Storage::getCurrent (swift_task_getCurrent ())) {
153+ Current->copyTo (target);
161154 }
162-
163- Local->copyTo (target);
164155}
165156
166- SWIFT_CC (swift)
167- static void swift_task_localsCopyToTaskGroupChildTaskDefensivelyImpl(AsyncTask *target) {
168- TaskLocal::Storage *Local = nullptr ;
157+ // =============================================================================
158+ // ==== Initialization ---------------------------------------------------------
169159
170- if (AsyncTask *task = swift_task_getCurrent ()) {
171- Local = &task->_private ().Local ;
160+ TaskLocal::Storage*
161+ TaskLocal::Storage::getCurrent (AsyncTask *current) {
162+ if (current) {
163+ return ¤t->_private ().Local ;
172164 } else if (auto *storage = FallbackTaskLocalStorage::get ()) {
173- Local = storage;
174- } else {
175- // bail out, there are no values to copy
176- return ;
165+ return storage;
177166 }
178167
179- Local-> copyToOnlyOnlyFromCurrent (target) ;
168+ return nullptr ;
180169}
181170
182- // =============================================================================
183- // ==== Initialization ---------------------------------------------------------
184-
185171void TaskLocal::Storage::initializeLinkParent (AsyncTask* task,
186172 AsyncTask* parent) {
187173 assert (!head && " initial task local storage was already initialized" );
@@ -501,7 +487,9 @@ void TaskLocal::Storage::copyTo(AsyncTask *target) {
501487 }
502488}
503489
504- void TaskLocal::Storage::copyToOnlyOnlyFromCurrent (AsyncTask *target) {
490+ // TODO(concurrency): This can be optimized to copy only from the CURRENT group,
491+ // but we need to detect this, e.g. by more flags in the items made from a group?
492+ void TaskLocal::Storage::copyToOnlyOnlyFromCurrentGroup (AsyncTask *target) {
505493 assert (target && " task must not be null when copying values into it" );
506494 assert (!(target->_private ().Local .head ) &&
507495 " Task must not have any task-local values bound before copying into it" );
@@ -525,7 +513,7 @@ void TaskLocal::Storage::copyToOnlyOnlyFromCurrent(AsyncTask *target) {
525513 // as we would have within normal child task relationships. E.g. this is
526514 // a parent or next pointer to a "safe" (withValue { withTaskGroup { ... } })
527515 // binding, so we re-link our current head to point at this item.
528- copiedHead->relinkNext (item);
516+ copiedHead->relinkTaskGroupLocalHeadToSafeNext (item);
529517 break ;
530518 }
531519
0 commit comments