5959#include " TaskPrivate.h"
6060#include " Error.h"
6161
62- #if !SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
62+ #if SWIFT_CONCURRENCY_ENABLE_DISPATCH
6363#include < dispatch/dispatch.h>
6464
6565#if !defined(_WIN32)
@@ -178,15 +178,21 @@ static Job *claimNextFromJobQueue() {
178178 }
179179}
180180
181- void swift::donateThreadToGlobalExecutorUntil (bool (*condition)(void *),
182- void *conditionContext) {
181+ void swift::
182+ swift_task_donateThreadToGlobalExecutorUntil (bool (*condition)(void *),
183+ void *conditionContext) {
183184 while (!condition (conditionContext)) {
184185 auto job = claimNextFromJobQueue ();
185186 if (!job) return ;
186187 swift_job_run (job, ExecutorRef::generic ());
187188 }
188189}
189190
191+ #elif !SWIFT_CONCURRENCY_ENABLE_DISPATCH
192+
193+ // No implementation. The expectation is that integrators in this
194+ // configuration will hook all the appropriate functions.
195+
190196#else
191197
192198// Ensure that Job's layout is compatible with what Dispatch expects.
@@ -330,6 +336,9 @@ static void swift_task_enqueueGlobalImpl(Job *job) {
330336
331337#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
332338 insertIntoJobQueue (job);
339+ #elif !SWIFT_CONCURRENCY_ENABLE_DISPATCH
340+ swift_reportError (0 , " operation unsupported without libdispatch: "
341+ " swift_task_enqueueGlobal" );
333342#else
334343 // We really want four things from the global execution service:
335344 // - Enqueuing work should have minimal runtime and memory overhead.
@@ -385,6 +394,9 @@ static void swift_task_enqueueGlobalWithDelayImpl(unsigned long long delay,
385394
386395#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
387396 insertIntoDelayedJobQueue (delay, job);
397+ #elif !SWIFT_CONCURRENCY_ENABLE_DISPATCH
398+ swift_reportError (0 , " operation unsupported without libdispatch: "
399+ " swift_task_enqueueGlobalWithDelay" );
388400#else
389401
390402 dispatch_function_t dispatchFunction = &__swift_run_job;
@@ -419,6 +431,9 @@ static void swift_task_enqueueMainExecutorImpl(Job *job) {
419431
420432#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
421433 insertIntoJobQueue (job);
434+ #elif !SWIFT_CONCURRENCY_ENABLE_DISPATCH
435+ swift_reportError (0 , " operation unsupported without libdispatch: "
436+ " swift_task_enqueueMainExecutor" );
422437#else
423438
424439 JobPriority priority = job->getPriority ();
@@ -439,7 +454,7 @@ void swift::swift_task_enqueueMainExecutor(Job *job) {
439454 swift_task_enqueueMainExecutorImpl (job);
440455}
441456
442- #if !SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
457+ #if SWIFT_CONCURRENCY_ENABLE_DISPATCH
443458void swift::swift_task_enqueueOnDispatchQueue (Job *job,
444459 HeapObject *_queue) {
445460 JobPriority priority = job->getPriority ();
@@ -449,7 +464,8 @@ void swift::swift_task_enqueueOnDispatchQueue(Job *job,
449464#endif
450465
451466ExecutorRef swift::swift_task_getMainExecutor () {
452- #if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
467+ #if !SWIFT_CONCURRENCY_ENABLE_DISPATCH
468+ // FIXME: this isn't right for the non-cooperative environment
453469 return ExecutorRef::generic ();
454470#else
455471 return ExecutorRef::forOrdinary (
@@ -459,7 +475,8 @@ ExecutorRef swift::swift_task_getMainExecutor() {
459475}
460476
461477bool ExecutorRef::isMainExecutor () const {
462- #if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
478+ #if !SWIFT_CONCURRENCY_ENABLE_DISPATCH
479+ // FIXME: this isn't right for the non-cooperative environment
463480 return isGeneric ();
464481#else
465482 return Identity == reinterpret_cast <HeapObject*>(&_dispatch_main_q);
0 commit comments