@@ -279,8 +279,10 @@ class TaskGroupImpl: public TaskGroupTaskStatusRecord {
279
279
280
280
private:
281
281
282
+ #if !SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
282
283
// TODO: move to lockless via the status atomic (make readyQueue an mpsc_queue_t<ReadyQueueItem>)
283
284
mutable std::mutex mutex;
285
+ #endif
284
286
285
287
// / Used for queue management, counting number of waiting and ready tasks
286
288
std::atomic <uint64_t > status;
@@ -559,7 +561,9 @@ void TaskGroupImpl::offer(AsyncTask *completedTask, AsyncContext *context) {
559
561
assert (completedTask->groupChildFragment ()->getGroup () == asAbstract (this ));
560
562
SWIFT_TASK_DEBUG_LOG (" offer task %p to group %p" , completedTask, this );
561
563
564
+ #if !SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
562
565
mutex.lock (); // TODO: remove fragment lock, and use status for synchronization
566
+ #endif
563
567
564
568
// Immediately increment ready count and acquire the status
565
569
// Examples:
@@ -597,7 +601,9 @@ void TaskGroupImpl::offer(AsyncTask *completedTask, AsyncContext *context) {
597
601
// Run the task.
598
602
auto result = PollResult::get (completedTask, hadErrorResult);
599
603
604
+ #if !SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
600
605
mutex.unlock (); // TODO: remove fragment lock, and use status for synchronization
606
+ #endif
601
607
602
608
auto waitingContext =
603
609
static_cast <TaskFutureWaitAsyncContext *>(
@@ -637,7 +643,9 @@ void TaskGroupImpl::offer(AsyncTask *completedTask, AsyncContext *context) {
637
643
assert (completedTask == readyItem.getTask ());
638
644
assert (readyItem.getTask ()->isFuture ());
639
645
readyQueue.enqueue (readyItem);
646
+ #if !SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
640
647
mutex.unlock (); // TODO: remove fragment lock, and use status for synchronization
648
+ #endif
641
649
return ;
642
650
}
643
651
@@ -722,7 +730,9 @@ static void swift_taskGroup_wait_next_throwingImpl(
722
730
}
723
731
724
732
PollResult TaskGroupImpl::poll (AsyncTask *waitingTask) {
733
+ #if !SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
725
734
mutex.lock (); // TODO: remove group lock, and use status for synchronization
735
+ #endif
726
736
SWIFT_TASK_DEBUG_LOG (" poll group = %p" , this );
727
737
auto assumed = statusMarkWaitingAssumeAcquire ();
728
738
@@ -740,7 +750,9 @@ PollResult TaskGroupImpl::poll(AsyncTask *waitingTask) {
740
750
statusRemoveWaiting ();
741
751
result.status = PollStatus::Empty;
742
752
result.successType = this ->successType ;
753
+ #if !SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
743
754
mutex.unlock (); // TODO: remove group lock, and use status for synchronization
755
+ #endif
744
756
return result;
745
757
}
746
758
@@ -787,7 +799,9 @@ PollResult TaskGroupImpl::poll(AsyncTask *waitingTask) {
787
799
result.successType = futureFragment->getResultType ();
788
800
assert (result.retainedTask && " polled a task, it must be not null" );
789
801
_swift_tsan_acquire (static_cast <Job *>(result.retainedTask ));
802
+ #if !SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
790
803
mutex.unlock (); // TODO: remove fragment lock, and use status for synchronization
804
+ #endif
791
805
return result;
792
806
793
807
case ReadyStatus::Error:
@@ -798,15 +812,19 @@ PollResult TaskGroupImpl::poll(AsyncTask *waitingTask) {
798
812
result.successType = nullptr ;
799
813
assert (result.retainedTask && " polled a task, it must be not null" );
800
814
_swift_tsan_acquire (static_cast <Job *>(result.retainedTask ));
815
+ #if !SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
801
816
mutex.unlock (); // TODO: remove fragment lock, and use status for synchronization
817
+ #endif
802
818
return result;
803
819
804
820
case ReadyStatus::Empty:
805
821
result.status = PollStatus::Empty;
806
822
result.storage = nullptr ;
807
823
result.retainedTask = nullptr ;
808
824
result.successType = this ->successType ;
825
+ #if !SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
809
826
mutex.unlock (); // TODO: remove fragment lock, and use status for synchronization
827
+ #endif
810
828
return result;
811
829
}
812
830
assert (false && " must return result when status compare-and-swap was successful" );
@@ -826,7 +844,9 @@ PollResult TaskGroupImpl::poll(AsyncTask *waitingTask) {
826
844
waitHead, waitingTask,
827
845
/* success*/ std::memory_order_release,
828
846
/* failure*/ std::memory_order_acquire)) {
847
+ #if !SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
829
848
mutex.unlock (); // TODO: remove fragment lock, and use status for synchronization
849
+ #endif
830
850
// no ready tasks, so we must wait.
831
851
result.status = PollStatus::MustWait;
832
852
_swift_task_clearCurrent ();
0 commit comments