[Concurrency] Improve in order synchronous enqueue of startSynchronously

Previously there was still a sneaky hop which caused ordering issues.
This introduced a specific test startSynchronously_order which checks
that the task enqueues indeed are "immediate" and cleans up how we
handle this.

This also prepares for the being discussed in SE review direction of
this API that it SHOULD be ALLOWED to actually hop and NOT be
synchronous at all IF the isolation is specified on the closure and is
DIFFERENT than the callers dynamic isolation.

This effectively implements "synchronously run right now if dynamically
on the exact isolation as requested by the closure; otherwise enqueue
the task as usual".

resolves rdar://149284186
cc @drexin
This commit is contained in:
Konrad 'ktoso' Malawski
2025-04-15 16:20:31 +09:00
parent 9efe4898d3
commit a24a28c217
8 changed files with 227 additions and 42 deletions

View File

@@ -1069,7 +1069,7 @@ SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
void swift_task_startOnMainActor(AsyncTask* job);
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
void swift_task_startSynchronously(AsyncTask* job);
void swift_task_startSynchronously(AsyncTask* job, SerialExecutorRef targetExecutor);
/// Donate this thread to the global executor until either the
/// given condition returns true or we've run out of cooperative