Skip to content

Commit a374939

Browse files
committed
[Concurrency] Call TaskGroupImpl destructor; stop leaking groups
1 parent c7dd41b commit a374939

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

stdlib/public/Concurrency/TaskGroup.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ static TaskGroup *asAbstract(TaskGroupImpl *group) {
454454
// Initializes into the preallocated _group an actual TaskGroupImpl.
455455
SWIFT_CC(swift)
456456
static void swift_taskGroup_initializeImpl(TaskGroup *group, const Metadata *T) {
457+
SWIFT_TASK_DEBUG_LOG("creating task group = %p", group);
458+
457459
TaskGroupImpl *impl = new (group) TaskGroupImpl(T);
458460
auto record = impl->getTaskRecord();
459461
assert(impl == record && "the group IS the task record");
@@ -472,8 +474,7 @@ static void swift_taskGroup_initializeImpl(TaskGroup *group, const Metadata *T)
472474
SWIFT_CC(swift)
473475
static void swift_taskGroup_attachChildImpl(TaskGroup *group,
474476
AsyncTask *child) {
475-
SWIFT_TASK_DEBUG_LOG("attach child task = %p to group = %p\n",
476-
child, group);
477+
SWIFT_TASK_DEBUG_LOG("attach child task = %p to group = %p", child, group);
477478

478479
// The counterpart of this (detachChild) is performed by the group itself,
479480
// when it offers the completed (child) task's value to a waiting task -
@@ -490,11 +491,17 @@ static void swift_taskGroup_destroyImpl(TaskGroup *group) {
490491
}
491492

492493
void TaskGroupImpl::destroy() {
494+
SWIFT_TASK_DEBUG_LOG("destroying task group = %p", this);
495+
493496
// First, remove the group from the task and deallocate the record
494497
swift_task_removeStatusRecord(getTaskRecord());
495498

496-
// By the time we call destroy, all tasks inside the group must have been
497-
// awaited on already; We handle this on the swift side.
499+
// No need to drain our queue here, as by the time we call destroy,
500+
// all tasks inside the group must have been awaited on already.
501+
// This is done in Swift's withTaskGroup function explicitly.
502+
503+
// destroy the group's storage
504+
this->~TaskGroupImpl();
498505
}
499506

500507
// =============================================================================
@@ -566,7 +573,7 @@ void TaskGroupImpl::offer(AsyncTask *completedTask, AsyncContext *context) {
566573
bool hadErrorResult = false;
567574
auto errorObject = asyncContextPrefix->errorResult;
568575
if (errorObject) {
569-
// instead we need to enqueue this result:
576+
// instead, we need to enqueue this result:
570577
hadErrorResult = true;
571578
}
572579

0 commit comments

Comments
 (0)