@@ -124,6 +124,7 @@ FutureFragment::Status AsyncTask::waitFuture(AsyncTask *waitingTask,
124
124
// Escalate the priority of this task based on the priority
125
125
// of the waiting task.
126
126
swift_task_escalate (this , waitingTask->Flags .getPriority ());
127
+ _swift_task_clearCurrent ();
127
128
return FutureFragment::Status::Executing;
128
129
}
129
130
}
@@ -937,7 +938,7 @@ size_t swift::swift_task_getJobFlags(AsyncTask *task) {
937
938
938
939
SWIFT_CC (swift)
939
940
static AsyncTask *swift_task_suspendImpl() {
940
- auto task = swift_task_getCurrent ();
941
+ auto task = _swift_task_clearCurrent ();
941
942
task->flagAsSuspended ();
942
943
return task;
943
944
}
@@ -963,16 +964,21 @@ static AsyncTask *swift_continuation_initImpl(ContinuationAsyncContext *context,
963
964
: ContinuationStatus::Pending,
964
965
std::memory_order_relaxed);
965
966
966
- auto task = swift_task_getCurrent ();
967
- assert (task && " initializing a continuation with no current task" );
968
- task->ResumeContext = context;
969
- task->ResumeTask = context->ResumeParent ;
967
+ AsyncTask *task;
970
968
971
969
// A preawait immediately suspends the task.
972
970
if (flags.isPreawaited ()) {
971
+ task = _swift_task_clearCurrent ();
972
+ assert (task && " initializing a continuation with no current task" );
973
973
task->flagAsSuspended ();
974
+ } else {
975
+ task = swift_task_getCurrent ();
976
+ assert (task && " initializing a continuation with no current task" );
974
977
}
975
978
979
+ task->ResumeContext = context;
980
+ task->ResumeTask = context->ResumeParent ;
981
+
976
982
return task;
977
983
}
978
984
@@ -1016,7 +1022,10 @@ static void swift_continuation_awaitImpl(ContinuationAsyncContext *context) {
1016
1022
/* failure*/ std::memory_order_acquire);
1017
1023
1018
1024
// If that succeeded, we have nothing to do.
1019
- if (success) return ;
1025
+ if (success) {
1026
+ _swift_task_clearCurrent ();
1027
+ return ;
1028
+ }
1020
1029
1021
1030
// If it failed, it should be because someone concurrently resumed
1022
1031
// (note that the compare-exchange above is strong).
0 commit comments