Skip to content

Commit d853f9b

Browse files
authored
Merge pull request swiftlang#39295 from ktoso/wip-dont-leak-queue-items
2 parents 5412ed1 + 1194300 commit d853f9b

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
@@ -455,6 +455,8 @@ static TaskGroup *asAbstract(TaskGroupImpl *group) {
455455
// Initializes into the preallocated _group an actual TaskGroupImpl.
456456
SWIFT_CC(swift)
457457
static void swift_taskGroup_initializeImpl(TaskGroup *group, const Metadata *T) {
458+
SWIFT_TASK_DEBUG_LOG("creating task group = %p", group);
459+
458460
TaskGroupImpl *impl = new (group) TaskGroupImpl(T);
459461
auto record = impl->getTaskRecord();
460462
assert(impl == record && "the group IS the task record");
@@ -473,8 +475,7 @@ static void swift_taskGroup_initializeImpl(TaskGroup *group, const Metadata *T)
473475
SWIFT_CC(swift)
474476
static void swift_taskGroup_attachChildImpl(TaskGroup *group,
475477
AsyncTask *child) {
476-
SWIFT_TASK_DEBUG_LOG("attach child task = %p to group = %p\n",
477-
child, group);
478+
SWIFT_TASK_DEBUG_LOG("attach child task = %p to group = %p", child, group);
478479

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

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

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

501508
// =============================================================================
@@ -567,7 +574,7 @@ void TaskGroupImpl::offer(AsyncTask *completedTask, AsyncContext *context) {
567574
bool hadErrorResult = false;
568575
auto errorObject = asyncContextPrefix->errorResult;
569576
if (errorObject) {
570-
// instead we need to enqueue this result:
577+
// instead, we need to enqueue this result:
571578
hadErrorResult = true;
572579
}
573580

0 commit comments

Comments
 (0)