@@ -38,6 +38,7 @@ struct OpaqueValue;
38
38
struct SwiftError ;
39
39
class TaskStatusRecord ;
40
40
class TaskDependencyStatusRecord ;
41
+ class TaskExecutorPreferenceStatusRecord ;
41
42
class TaskOptionRecord ;
42
43
class TaskGroup ;
43
44
class ContinuationAsyncContext ;
@@ -399,7 +400,7 @@ class AsyncTask : public Job {
399
400
400
401
public:
401
402
// / Flag that the task is to be enqueued on the provided executor and actually
402
- // / enqueue it
403
+ // / enqueue it.
403
404
void flagAsAndEnqueueOnExecutor (SerialExecutorRef newExecutor);
404
405
405
406
// / Flag that this task is now completed. This normally does not do anything
@@ -410,6 +411,30 @@ class AsyncTask : public Job {
410
411
// / Checking this is, of course, inherently race-prone on its own.
411
412
bool isCancelled () const ;
412
413
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
+
413
438
// ==== Task Local Values ----------------------------------------------------
414
439
415
440
void localValuePush (const HeapObject *key,
@@ -513,6 +538,26 @@ class AsyncTask : public Job {
513
538
return reinterpret_cast <GroupChildFragment *>(offset);
514
539
}
515
540
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
+
516
561
// ==== Future ---------------------------------------------------------------
517
562
518
563
class FutureFragment {
0 commit comments