@@ -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,71 +767,29 @@ 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);
768-
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);
796-
797-
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.
821- typedef SWIFT_CC (swift) void (*swift_task_asyncMainDrainQueue_original)();
822- typedef SWIFT_CC (swift) void (*swift_task_asyncMainDrainQueue_override)(
823- swift_task_asyncMainDrainQueue_original original);
824- SWIFT_EXPORT_FROM (swift_Concurrency)
825- SWIFT_CC (swift) void (*swift_task_asyncMainDrainQueue_hook)(
826- swift_task_asyncMainDrainQueue_original original,
827- swift_task_asyncMainDrainQueue_override compatOverride);
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
776+
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
782+
783+ #define SWIFT_CONCURRENCY_HOOK_OVERRIDE0 (returnType, name ) \
784+ typedef SWIFT_CC (swift) returnType (*name##_original)(); \
785+ typedef SWIFT_CC (swift) returnType (*name##_override)( \
786+ name##_original original); \
787+ typedef SWIFT_CC (swift) returnType \
788+ (*name##_hook_t )(name##_original original, \
789+ name##_override compatOverride); \
790+ SWIFT_EXPORT_FROM (swift_Concurrency) name##_hook_t name##_hook
791+
792+ #include " ConcurrencyHooks.def"
828793
829794// / Initialize the runtime storage for a default actor.
830795SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
@@ -951,6 +916,10 @@ SerialExecutorRef swift_task_getCurrentExecutor(void);
951916SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
952917SerialExecutorRef swift_task_getMainExecutor (void );
953918
919+ // / Test if an executor is the main executor.
920+ SWIFT_EXPORT_FROM (swift_Concurrency) SWIFT_CC(swift)
921+ bool swift_task_isMainExecutor (SerialExecutorRef executor);
922+
954923// / Return the preferred task executor of the current task,
955924// / or ``TaskExecutorRef::undefined()`` if no preference.
956925// /
0 commit comments