@@ -279,8 +279,16 @@ class TaskGroupImpl: public TaskGroupTaskStatusRecord {
279279
280280private:
281281
282+ #if !SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
282283 // TODO: move to lockless via the status atomic (make readyQueue an mpsc_queue_t<ReadyQueueItem>)
283- mutable std::mutex mutex;
284+ mutable std::mutex mutex_;
285+
286+ void lock () const { mutex_.lock (); }
287+ void unlock () const { mutex_.unlock (); }
288+ #else
289+ void lock () const {}
290+ void unlock () const {}
291+ #endif
284292
285293 // / Used for queue management, counting number of waiting and ready tasks
286294 std::atomic <uint64_t > status;
@@ -557,7 +565,7 @@ void TaskGroupImpl::offer(AsyncTask *completedTask, AsyncContext *context) {
557565 assert (completedTask->groupChildFragment ()->getGroup () == asAbstract (this ));
558566 SWIFT_TASK_DEBUG_LOG (" offer task %p to group %p" , completedTask, this );
559567
560- mutex. lock (); // TODO: remove fragment lock, and use status for synchronization
568+ lock (); // TODO: remove fragment lock, and use status for synchronization
561569
562570 // Immediately increment ready count and acquire the status
563571 // Examples:
@@ -595,7 +603,7 @@ void TaskGroupImpl::offer(AsyncTask *completedTask, AsyncContext *context) {
595603 // Run the task.
596604 auto result = PollResult::get (completedTask, hadErrorResult);
597605
598- mutex. unlock (); // TODO: remove fragment lock, and use status for synchronization
606+ unlock (); // TODO: remove fragment lock, and use status for synchronization
599607
600608 auto waitingContext =
601609 static_cast <TaskFutureWaitAsyncContext *>(
@@ -635,7 +643,7 @@ void TaskGroupImpl::offer(AsyncTask *completedTask, AsyncContext *context) {
635643 assert (completedTask == readyItem.getTask ());
636644 assert (readyItem.getTask ()->isFuture ());
637645 readyQueue.enqueue (readyItem);
638- mutex. unlock (); // TODO: remove fragment lock, and use status for synchronization
646+ unlock (); // TODO: remove fragment lock, and use status for synchronization
639647 return ;
640648}
641649
@@ -720,7 +728,7 @@ static void swift_taskGroup_wait_next_throwingImpl(
720728}
721729
722730PollResult TaskGroupImpl::poll (AsyncTask *waitingTask) {
723- mutex. lock (); // TODO: remove group lock, and use status for synchronization
731+ lock (); // TODO: remove group lock, and use status for synchronization
724732 SWIFT_TASK_DEBUG_LOG (" poll group = %p" , this );
725733 auto assumed = statusMarkWaitingAssumeAcquire ();
726734
@@ -738,7 +746,7 @@ PollResult TaskGroupImpl::poll(AsyncTask *waitingTask) {
738746 statusRemoveWaiting ();
739747 result.status = PollStatus::Empty;
740748 result.successType = this ->successType ;
741- mutex. unlock (); // TODO: remove group lock, and use status for synchronization
749+ unlock (); // TODO: remove group lock, and use status for synchronization
742750 return result;
743751 }
744752
@@ -785,7 +793,7 @@ PollResult TaskGroupImpl::poll(AsyncTask *waitingTask) {
785793 result.successType = futureFragment->getResultType ();
786794 assert (result.retainedTask && " polled a task, it must be not null" );
787795 _swift_tsan_acquire (static_cast <Job *>(result.retainedTask ));
788- mutex. unlock (); // TODO: remove fragment lock, and use status for synchronization
796+ unlock (); // TODO: remove fragment lock, and use status for synchronization
789797 return result;
790798
791799 case ReadyStatus::Error:
@@ -796,15 +804,15 @@ PollResult TaskGroupImpl::poll(AsyncTask *waitingTask) {
796804 result.successType = nullptr ;
797805 assert (result.retainedTask && " polled a task, it must be not null" );
798806 _swift_tsan_acquire (static_cast <Job *>(result.retainedTask ));
799- mutex. unlock (); // TODO: remove fragment lock, and use status for synchronization
807+ unlock (); // TODO: remove fragment lock, and use status for synchronization
800808 return result;
801809
802810 case ReadyStatus::Empty:
803811 result.status = PollStatus::Empty;
804812 result.storage = nullptr ;
805813 result.retainedTask = nullptr ;
806814 result.successType = this ->successType ;
807- mutex. unlock (); // TODO: remove fragment lock, and use status for synchronization
815+ unlock (); // TODO: remove fragment lock, and use status for synchronization
808816 return result;
809817 }
810818 assert (false && " must return result when status compare-and-swap was successful" );
@@ -824,7 +832,7 @@ PollResult TaskGroupImpl::poll(AsyncTask *waitingTask) {
824832 waitHead, waitingTask,
825833 /* success*/ std::memory_order_release,
826834 /* failure*/ std::memory_order_acquire)) {
827- mutex. unlock (); // TODO: remove fragment lock, and use status for synchronization
835+ unlock (); // TODO: remove fragment lock, and use status for synchronization
828836 // no ready tasks, so we must wait.
829837 result.status = PollStatus::MustWait;
830838 _swift_task_clearCurrent ();
0 commit comments