@@ -720,6 +720,13 @@ void swift_task_enqueueGlobal(Job *job);
720
720
SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
721
721
void swift_task_checkIsolated (SerialExecutorRef executor);
722
722
723
+ // / Invoke a Swift executor's `checkIsolated` implementation; returns
724
+ // / `true` if it invoked the Swift implementation, `false` otherwise.
725
+ // / Executors will want to call this from their `swift_task_checkIsolatedImpl`
726
+ // / implementation.
727
+ SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
728
+ bool swift_task_invokeSwiftCheckIsolated (SerialExecutorRef executor);
729
+
723
730
// / A count in nanoseconds.
724
731
using JobDelay = unsigned long long ;
725
732
@@ -760,64 +767,22 @@ void swift_task_enqueueOnDispatchQueue(Job *job, HeapObject *queue);
760
767
761
768
#endif
762
769
763
- // / A hook to take over global enqueuing.
764
- typedef SWIFT_CC (swift) void (*swift_task_enqueueGlobal_original)(Job *job);
765
- SWIFT_EXPORT_FROM (swift_Concurrency)
766
- SWIFT_CC (swift) void (*swift_task_enqueueGlobal_hook)(
767
- Job *job, swift_task_enqueueGlobal_original original);
770
+ // Declare all the hooks
771
+ #define SWIFT_CONCURRENCY_HOOK (returnType, name, ...) \
772
+ typedef SWIFT_CC (swift) returnType (*name##_original)(__VA_ARGS__); \
773
+ typedef SWIFT_CC (swift) returnType \
774
+ (*name##_hook_t )(__VA_ARGS__, name##_original original); \
775
+ SWIFT_EXPORT_FROM (swift_Concurrency) name##_hook_t name##_hook
768
776
769
- // / A hook to take over global enqueuing with delay.
770
- typedef SWIFT_CC (swift) void (*swift_task_enqueueGlobalWithDelay_original)(
771
- unsigned long long delay, Job *job);
772
- SWIFT_EXPORT_FROM (swift_Concurrency)
773
- SWIFT_CC (swift) void (*swift_task_enqueueGlobalWithDelay_hook)(
774
- unsigned long long delay, Job *job,
775
- swift_task_enqueueGlobalWithDelay_original original);
776
-
777
- typedef SWIFT_CC (swift) void (*swift_task_enqueueGlobalWithDeadline_original)(
778
- long long sec,
779
- long long nsec,
780
- long long tsec,
781
- long long tnsec,
782
- int clock, Job *job);
783
- SWIFT_EXPORT_FROM (swift_Concurrency)
784
- SWIFT_CC (swift) void (*swift_task_enqueueGlobalWithDeadline_hook)(
785
- long long sec,
786
- long long nsec,
787
- long long tsec,
788
- long long tnsec,
789
- int clock, Job *job,
790
- swift_task_enqueueGlobalWithDeadline_original original);
791
-
792
- typedef SWIFT_CC (swift) void (*swift_task_checkIsolated_original)(SerialExecutorRef executor);
793
- SWIFT_EXPORT_FROM (swift_Concurrency)
794
- SWIFT_CC (swift) void (*swift_task_checkIsolated_hook)(
795
- SerialExecutorRef executor, swift_task_checkIsolated_original original);
777
+ #define SWIFT_CONCURRENCY_HOOK0 (returnType, name ) \
778
+ typedef SWIFT_CC (swift) returnType (*name##_original)(); \
779
+ typedef SWIFT_CC (swift) returnType \
780
+ (*name##_hook_t )(name##_original original); \
781
+ SWIFT_EXPORT_FROM (swift_Concurrency) name##_hook_t name##_hook
796
782
783
+ #include " ConcurrencyHooks.def"
797
784
798
- typedef SWIFT_CC (swift) bool (*swift_task_isOnExecutor_original)(
799
- HeapObject *executor,
800
- const Metadata *selfType,
801
- const SerialExecutorWitnessTable *wtable);
802
- SWIFT_EXPORT_FROM (swift_Concurrency)
803
- SWIFT_CC (swift) bool (*swift_task_isOnExecutor_hook)(
804
- HeapObject *executor,
805
- const Metadata *selfType,
806
- const SerialExecutorWitnessTable *wtable,
807
- swift_task_isOnExecutor_original original);
808
-
809
- // / A hook to take over main executor enqueueing.
810
- typedef SWIFT_CC (swift) void (*swift_task_enqueueMainExecutor_original)(
811
- Job *job);
812
- SWIFT_EXPORT_FROM (swift_Concurrency)
813
- SWIFT_CC (swift) void (*swift_task_enqueueMainExecutor_hook)(
814
- Job *job, swift_task_enqueueMainExecutor_original original);
815
-
816
- // / A hook to override the entrypoint to the main runloop used to drive the
817
- // / concurrency runtime and drain the main queue. This function must not return.
818
- // / Note: If the hook is wrapping the original function and the `compatOverride`
819
- // / is passed in, the `original` function pointer must be passed into the
820
- // / compatibility override function as the original function.
785
+ // This is a compatibility hook, *not* a concurrency hook
821
786
typedef SWIFT_CC (swift) void (*swift_task_asyncMainDrainQueue_original)();
822
787
typedef SWIFT_CC (swift) void (*swift_task_asyncMainDrainQueue_override)(
823
788
swift_task_asyncMainDrainQueue_original original);
@@ -913,11 +878,16 @@ extern "C" SWIFT_CC(swift)
913
878
void swift_continuation_logFailedCheck (const char *message);
914
879
915
880
// / Drain the queue
916
- // / If the binary links CoreFoundation, uses CFRunLoopRun
917
- // / Otherwise it uses dispatchMain.
918
881
SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
919
882
void swift_task_asyncMainDrainQueue [[noreturn]]();
920
883
884
+ // / Drain the global executor. This does the same as the above, but
885
+ // / swift_task_asyncMainDrainQueue() is a compatibility override point,
886
+ // / whereas this function has a concurrency hook. The default
887
+ // / swift_task_asyncMainDrainQueue() implementation just calls this function.
888
+ SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
889
+ void swift_task_drainGlobalExecutor [[noreturn]]();
890
+
921
891
// / Establish that the current thread is running as the given
922
892
// / executor, then run a job.
923
893
SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
@@ -951,6 +921,10 @@ SerialExecutorRef swift_task_getCurrentExecutor(void);
951
921
SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
952
922
SerialExecutorRef swift_task_getMainExecutor (void );
953
923
924
+ // / Test if an executor is the main executor.
925
+ SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
926
+ bool swift_task_isMainExecutor (SerialExecutorRef executor);
927
+
954
928
// / Return the preferred task executor of the current task,
955
929
// / or ``TaskExecutorRef::undefined()`` if no preference.
956
930
// /
@@ -984,17 +958,13 @@ JobPriority swift_task_getCurrentThreadPriority(void);
984
958
SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
985
959
void swift_task_startOnMainActor (AsyncTask* job);
986
960
987
- #if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
988
-
989
961
// / Donate this thread to the global executor until either the
990
962
// / given condition returns true or we've run out of cooperative
991
963
// / tasks to run.
992
964
SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
993
965
void swift_task_donateThreadToGlobalExecutorUntil (bool (*condition)(void *),
994
966
void *context);
995
967
996
- #endif
997
-
998
968
enum swift_clock_id : int {
999
969
swift_clock_id_continuous = 1 ,
1000
970
swift_clock_id_suspending = 2
0 commit comments