@@ -455,6 +455,8 @@ static TaskGroup *asAbstract(TaskGroupImpl *group) {
455
455
// Initializes into the preallocated _group an actual TaskGroupImpl.
456
456
SWIFT_CC (swift)
457
457
static void swift_taskGroup_initializeImpl(TaskGroup *group, const Metadata *T) {
458
+ SWIFT_TASK_DEBUG_LOG (" creating task group = %p" , group);
459
+
458
460
TaskGroupImpl *impl = new (group) TaskGroupImpl (T);
459
461
auto record = impl->getTaskRecord ();
460
462
assert (impl == record && " the group IS the task record" );
@@ -473,8 +475,7 @@ static void swift_taskGroup_initializeImpl(TaskGroup *group, const Metadata *T)
473
475
SWIFT_CC (swift)
474
476
static void swift_taskGroup_attachChildImpl(TaskGroup *group,
475
477
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);
478
479
479
480
// The counterpart of this (detachChild) is performed by the group itself,
480
481
// when it offers the completed (child) task's value to a waiting task -
@@ -491,11 +492,17 @@ static void swift_taskGroup_destroyImpl(TaskGroup *group) {
491
492
}
492
493
493
494
void TaskGroupImpl::destroy () {
495
+ SWIFT_TASK_DEBUG_LOG (" destroying task group = %p" , this );
496
+
494
497
// First, remove the group from the task and deallocate the record
495
498
swift_task_removeStatusRecord (getTaskRecord ());
496
499
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 ();
499
506
}
500
507
501
508
// =============================================================================
@@ -567,7 +574,7 @@ void TaskGroupImpl::offer(AsyncTask *completedTask, AsyncContext *context) {
567
574
bool hadErrorResult = false ;
568
575
auto errorObject = asyncContextPrefix->errorResult ;
569
576
if (errorObject) {
570
- // instead we need to enqueue this result:
577
+ // instead, we need to enqueue this result:
571
578
hadErrorResult = true ;
572
579
}
573
580
0 commit comments