@@ -720,6 +720,13 @@ void swift_task_enqueueGlobal(Job *job);
720720SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
721721void swift_task_checkIsolated (SerialExecutorRef executor);
722722
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+
723730// / A count in nanoseconds.
724731using JobDelay = unsigned long long ;
725732
@@ -760,64 +767,22 @@ void swift_task_enqueueOnDispatchQueue(Job *job, HeapObject *queue);
760767
761768#endif
762769
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
768776
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
796782
783+ #include " ConcurrencyHooks.def"
797784
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
821786typedef SWIFT_CC (swift) void (*swift_task_asyncMainDrainQueue_original)();
822787typedef SWIFT_CC (swift) void (*swift_task_asyncMainDrainQueue_override)(
823788 swift_task_asyncMainDrainQueue_original original);
@@ -913,11 +878,16 @@ extern "C" SWIFT_CC(swift)
913878void swift_continuation_logFailedCheck (const char *message);
914879
915880// / Drain the queue
916- // / If the binary links CoreFoundation, uses CFRunLoopRun
917- // / Otherwise it uses dispatchMain.
918881SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
919882void swift_task_asyncMainDrainQueue [[noreturn]]();
920883
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+
921891// / Establish that the current thread is running as the given
922892// / executor, then run a job.
923893SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
@@ -951,6 +921,10 @@ SerialExecutorRef swift_task_getCurrentExecutor(void);
951921SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
952922SerialExecutorRef swift_task_getMainExecutor (void );
953923
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+
954928// / Return the preferred task executor of the current task,
955929// / or ``TaskExecutorRef::undefined()`` if no preference.
956930// /
@@ -984,17 +958,13 @@ JobPriority swift_task_getCurrentThreadPriority(void);
984958SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
985959void swift_task_startOnMainActor (AsyncTask* job);
986960
987- #if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
988-
989961// / Donate this thread to the global executor until either the
990962// / given condition returns true or we've run out of cooperative
991963// / tasks to run.
992964SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
993965void swift_task_donateThreadToGlobalExecutorUntil (bool (*condition)(void *),
994966 void *context);
995967
996- #endif
997-
998968enum swift_clock_id : int {
999969 swift_clock_id_continuous = 1 ,
1000970 swift_clock_id_suspending = 2
0 commit comments