@@ -228,7 +228,7 @@ class TaskGroupBase : public TaskGroupTaskStatusRecord {
228
228
reinterpret_cast <OpaqueValue *>(fragment->getError ()) :
229
229
fragment->getStoragePtr (),
230
230
/* successType=*/ fragment->getResultType (),
231
- /* task =*/ asyncTask
231
+ /* retainedTask= =*/ asyncTask
232
232
};
233
233
}
234
234
@@ -1040,7 +1040,7 @@ static void fillGroupNextResult(TaskFutureWaitAsyncContext *context,
1040
1040
1041
1041
case PollStatus::Error: {
1042
1042
auto error = reinterpret_cast <SwiftError *>(result.storage );
1043
- fillGroupNextErrorResult (context, error);
1043
+ fillGroupNextErrorResult (context, error); // FIXME: this specifically retains the error, but likely should not!??!!?
1044
1044
return ;
1045
1045
}
1046
1046
@@ -1218,7 +1218,6 @@ void DiscardingTaskGroup::offer(AsyncTask *completedTask, AsyncContext *context)
1218
1218
// We can do this, since in this mode there is no ready count to keep track of,
1219
1219
// and we immediately discard the result.
1220
1220
auto afterComplete = statusCompletePendingAssumeRelease ();
1221
- (void ) afterComplete;
1222
1221
const bool alreadyDecrementedStatus = true ;
1223
1222
SWIFT_TASK_GROUP_DEBUG_LOG (this , " offer, complete, status afterComplete:%s" , afterComplete.to_string (this ).c_str ());
1224
1223
@@ -1351,8 +1350,8 @@ void TaskGroupBase::resumeWaitingTask(
1351
1350
// Run the task.
1352
1351
auto result = PollResult::get (completedTask, hadErrorResult);
1353
1352
SWIFT_TASK_GROUP_DEBUG_LOG (this ,
1354
- " resume waiting DONE, task = %p, backup = %p, error:%d, complete with = %p, status = %s" ,
1355
- waitingTask, backup, hadErrorResult, completedTask, statusString ().c_str ());
1353
+ " resume waiting DONE, task = %p, error:%d, complete with = %p, status = %s" ,
1354
+ waitingTask, hadErrorResult, completedTask, statusString ().c_str ());
1356
1355
1357
1356
auto waitingContext =
1358
1357
static_cast <TaskFutureWaitAsyncContext *>(
@@ -1369,6 +1368,11 @@ void TaskGroupBase::resumeWaitingTask(
1369
1368
// locks) because we know that the child task is completed and
1370
1369
// we can't be holding its locks ourselves.
1371
1370
_swift_taskGroup_detachChild (asAbstract (this ), completedTask);
1371
+ if (hadErrorResult) {
1372
+ // We only used the task to keep the error in the future fragment around
1373
+ // so now that we emitted the error and detached the task, we are free to release the task immediately.
1374
+ swift_release (completedTask);
1375
+ }
1372
1376
1373
1377
_swift_tsan_acquire (static_cast <Job *>(waitingTask));
1374
1378
// TODO: allow the caller to suggest an executor
@@ -1377,7 +1381,7 @@ void TaskGroupBase::resumeWaitingTask(
1377
1381
#endif /* SWIFT_CONCURRENCY_TASK_TO_THREAD_MODEL */
1378
1382
} else {
1379
1383
SWIFT_TASK_GROUP_DEBUG_LOG (this , " CAS failed, task = %p, backup = %p, complete with = %p, status = %s" ,
1380
- waitingTask, backup, completedTask, statusString ().c_str ());
1384
+ waitingTask, completedTask, statusString ().c_str ());
1381
1385
}
1382
1386
}
1383
1387
}
0 commit comments