@@ -38,6 +38,7 @@ struct OpaqueValue;
3838struct SwiftError ;
3939class TaskStatusRecord ;
4040class TaskDependencyStatusRecord ;
41+ class TaskExecutorPreferenceStatusRecord ;
4142class TaskOptionRecord ;
4243class TaskGroup ;
4344class ContinuationAsyncContext ;
@@ -399,7 +400,7 @@ class AsyncTask : public Job {
399400
400401public:
401402 // / Flag that the task is to be enqueued on the provided executor and actually
402- // / enqueue it
403+ // / enqueue it.
403404 void flagAsAndEnqueueOnExecutor (SerialExecutorRef newExecutor);
404405
405406 // / Flag that this task is now completed. This normally does not do anything
@@ -410,6 +411,30 @@ class AsyncTask : public Job {
410411 // / Checking this is, of course, inherently race-prone on its own.
411412 bool isCancelled () const ;
412413
414+ // ==== Task Executor Preference ---------------------------------------------
415+
416+ // / Get the preferred task executor reference if there is one set for this
417+ // / task.
418+ TaskExecutorRef getPreferredTaskExecutor ();
419+
420+ // / WARNING: Only to be used during task creation, in other situations prefer
421+ // / to use `swift_task_pushTaskExecutorPreference` and
422+ // / `swift_task_popTaskExecutorPreference`.
423+ void pushInitialTaskExecutorPreference (TaskExecutorRef preferred);
424+
425+ // / WARNING: Only to be used during task completion (destroy).
426+ // /
427+ // / This is because between task creation and its destory, we cannot carry the
428+ // / exact record to `pop(record)`, and instead assume that there will be
429+ // / exactly one record remaining -- the "initial" record (added during
430+ // / creating the task), and it must be that record that is removed by this
431+ // / api.
432+ // /
433+ // / All other situations from user code should be using the
434+ // / `swift_task_pushTaskExecutorPreference`, and
435+ // / `swift_task_popTaskExecutorPreference(record)` method pair.
436+ void dropInitialTaskExecutorPreferenceRecord ();
437+
413438 // ==== Task Local Values ----------------------------------------------------
414439
415440 void localValuePush (const HeapObject *key,
@@ -513,6 +538,26 @@ class AsyncTask : public Job {
513538 return reinterpret_cast <GroupChildFragment *>(offset);
514539 }
515540
541+ // ==== Task Executor Preference --------------------------------------------
542+
543+ // / Returns true if the task has a task executor preference set,
544+ // / specifically at creation time of the task. This may be from
545+ // / inheriting the preference from a parent task, or by explicitly
546+ // / setting it during creation (`Task(_on:...)`).
547+ // /
548+ // / This means that during task tear down the record should be deallocated
549+ // / because it will not be taken care of by a paired "pop" as the normal
550+ // / user-land "push / pop" pair of setting a task executor preference would
551+ // / have been.
552+ bool hasInitialTaskExecutorPreferenceRecord () const {
553+ return Flags.task_hasInitialTaskExecutorPreference ();
554+ }
555+
556+ // / Returns true if the current task has any task preference record,
557+ // / including if it has an initial task preference record or onces
558+ // / set during the lifetime of the task.
559+ bool hasTaskExecutorPreferenceRecord () const ;
560+
516561 // ==== Future ---------------------------------------------------------------
517562
518563 class FutureFragment {
0 commit comments