31
31
#include " swift/Basic/STLExtras.h"
32
32
#include " swift/Runtime/Concurrency.h"
33
33
#include " swift/Runtime/Config.h"
34
+ #include " swift/Runtime/Heap.h"
34
35
#include " swift/Runtime/HeapObject.h"
35
36
#include " swift/Threading/Mutex.h"
36
37
#include < atomic>
38
+ #include < deque>
37
39
#include < new>
38
40
39
41
#if SWIFT_STDLIB_HAS_ASL
@@ -114,7 +116,7 @@ class DiscardingTaskGroup;
114
116
115
117
template <typename T>
116
118
class NaiveTaskGroupQueue {
117
- std::queue <T > queue;
119
+ std::queue<T, std::deque<T, swift::cxx_allocator<T>> > queue;
118
120
119
121
public:
120
122
NaiveTaskGroupQueue () = default ;
@@ -346,6 +348,11 @@ class TaskGroupBase : public TaskGroupTaskStatusRecord {
346
348
public:
347
349
virtual ~TaskGroupBase () {}
348
350
351
+ // / Because we have a virtual destructor, we need to declare a delete operator
352
+ // / here, otherwise the compiler will generate a deleting destructor that
353
+ // / calls ::operator delete.
354
+ SWIFT_CXX_DELETE_OPERATOR (TaskGroupBase)
355
+
349
356
TaskStatusRecordKind getKind () const {
350
357
return Flags.getKind ();
351
358
}
@@ -419,7 +426,9 @@ class TaskGroupBase : public TaskGroupTaskStatusRecord {
419
426
TaskGroupStatus statusLoadRelaxed () const ;
420
427
TaskGroupStatus statusLoadAcquire () const ;
421
428
429
+ #if !SWIFT_CONCURRENCY_EMBEDDED
422
430
std::string statusString () const ;
431
+ #endif
423
432
424
433
bool isEmpty () const ;
425
434
@@ -469,6 +478,7 @@ class TaskGroupBase : public TaskGroupTaskStatusRecord {
469
478
470
479
};
471
480
481
+ #if !SWIFT_CONCURRENCY_EMBEDDED
472
482
[[maybe_unused]]
473
483
static std::string to_string (TaskGroupBase::PollStatus status) {
474
484
switch (status) {
@@ -478,6 +488,7 @@ static std::string to_string(TaskGroupBase::PollStatus status) {
478
488
case TaskGroupBase::PollStatus::Error: return " Error" ;
479
489
}
480
490
}
491
+ #endif
481
492
482
493
// / The status of a task group.
483
494
// /
@@ -579,7 +590,13 @@ struct TaskGroupStatus {
579
590
swift_asprintf (
580
591
&message,
581
592
" error: %sTaskGroup: detected pending task count overflow, in task group %p! Status: %s" ,
582
- group->isDiscardingResults () ? " Discarding" : " " , group, status.to_string (group).c_str ());
593
+ group->isDiscardingResults () ? " Discarding" : " " , group,
594
+ #if !SWIFT_CONCURRENCY_EMBEDDED
595
+ status.to_string (group).c_str ()
596
+ #else
597
+ " <status unavailable in embedded>"
598
+ #endif
599
+ );
583
600
584
601
#if !SWIFT_CONCURRENCY_EMBEDDED
585
602
if (_swift_shouldReportFatalErrorsToDebugger ()) {
@@ -612,6 +629,7 @@ struct TaskGroupStatus {
612
629
abort ();
613
630
}
614
631
632
+ #if !SWIFT_CONCURRENCY_EMBEDDED
615
633
// / Pretty prints the status, as follows:
616
634
// / If accumulating results:
617
635
// / TaskGroupStatus{ C:{cancelled} W:{waiting task} R:{ready tasks} P:{pending tasks} {binary repr} }
@@ -634,6 +652,7 @@ struct TaskGroupStatus {
634
652
str.append (" }" );
635
653
return str;
636
654
}
655
+ #endif // !SWIFT_CONCURRENCY_EMBEDDED
637
656
638
657
// / Initially there are no waiting and no pending tasks.
639
658
static const TaskGroupStatus initial () {
@@ -691,9 +710,11 @@ TaskGroupStatus TaskGroupBase::statusLoadAcquire() const {
691
710
return TaskGroupStatus{status.load (std::memory_order_acquire)};
692
711
}
693
712
713
+ #if !SWIFT_CONCURRENCY_EMBEDDED
694
714
std::string TaskGroupBase::statusString () const {
695
715
return statusLoadRelaxed ().to_string (this );
696
716
}
717
+ #endif
697
718
698
719
bool TaskGroupBase::isEmpty () const {
699
720
auto oldStatus = TaskGroupStatus{status.load (std::memory_order_relaxed)};
@@ -749,6 +770,7 @@ TaskGroupStatus TaskGroupBase::statusAddPendingTaskAssumeRelaxed(bool unconditio
749
770
}
750
771
751
772
SWIFT_TASK_GROUP_DEBUG_LOG (this , " addPending, after: %s" , s.to_string (this ).c_str ());
773
+
752
774
return s;
753
775
}
754
776
@@ -967,13 +989,13 @@ static void swift_taskGroup_initializeImpl(TaskGroup *group, const Metadata *T)
967
989
SWIFT_CC (swift)
968
990
static void swift_taskGroup_initializeWithFlagsImpl(size_t rawGroupFlags,
969
991
TaskGroup *group, const Metadata *T) {
970
- ResultTypeInfo resultType;
971
992
#if !SWIFT_CONCURRENCY_EMBEDDED
993
+ ResultTypeInfo resultType;
972
994
resultType.metadata = T;
995
+ _swift_taskGroup_initialize (resultType, rawGroupFlags, group);
973
996
#else
974
997
swift_unreachable (" swift_taskGroup_initializeWithFlags in embedded" );
975
998
#endif
976
- _swift_taskGroup_initialize (resultType, rawGroupFlags, group);
977
999
}
978
1000
979
1001
// Initializes into the preallocated _group an actual instance.
0 commit comments