59
59
#include " TaskPrivate.h"
60
60
#include " Error.h"
61
61
62
- #if !SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
62
+ #if SWIFT_CONCURRENCY_ENABLE_DISPATCH
63
63
#include < dispatch/dispatch.h>
64
64
65
65
#if !defined(_WIN32)
@@ -178,15 +178,21 @@ static Job *claimNextFromJobQueue() {
178
178
}
179
179
}
180
180
181
- void swift::donateThreadToGlobalExecutorUntil (bool (*condition)(void *),
182
- void *conditionContext) {
181
+ void swift::
182
+ swift_task_donateThreadToGlobalExecutorUntil (bool (*condition)(void *),
183
+ void *conditionContext) {
183
184
while (!condition (conditionContext)) {
184
185
auto job = claimNextFromJobQueue ();
185
186
if (!job) return ;
186
187
swift_job_run (job, ExecutorRef::generic ());
187
188
}
188
189
}
189
190
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
+
190
196
#else
191
197
192
198
// Ensure that Job's layout is compatible with what Dispatch expects.
@@ -330,6 +336,9 @@ static void swift_task_enqueueGlobalImpl(Job *job) {
330
336
331
337
#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
332
338
insertIntoJobQueue (job);
339
+ #elif !SWIFT_CONCURRENCY_ENABLE_DISPATCH
340
+ swift_reportError (0 , " operation unsupported without libdispatch: "
341
+ " swift_task_enqueueGlobal" );
333
342
#else
334
343
// We really want four things from the global execution service:
335
344
// - Enqueuing work should have minimal runtime and memory overhead.
@@ -385,6 +394,9 @@ static void swift_task_enqueueGlobalWithDelayImpl(unsigned long long delay,
385
394
386
395
#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
387
396
insertIntoDelayedJobQueue (delay, job);
397
+ #elif !SWIFT_CONCURRENCY_ENABLE_DISPATCH
398
+ swift_reportError (0 , " operation unsupported without libdispatch: "
399
+ " swift_task_enqueueGlobalWithDelay" );
388
400
#else
389
401
390
402
dispatch_function_t dispatchFunction = &__swift_run_job;
@@ -419,6 +431,9 @@ static void swift_task_enqueueMainExecutorImpl(Job *job) {
419
431
420
432
#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
421
433
insertIntoJobQueue (job);
434
+ #elif !SWIFT_CONCURRENCY_ENABLE_DISPATCH
435
+ swift_reportError (0 , " operation unsupported without libdispatch: "
436
+ " swift_task_enqueueMainExecutor" );
422
437
#else
423
438
424
439
JobPriority priority = job->getPriority ();
@@ -439,7 +454,7 @@ void swift::swift_task_enqueueMainExecutor(Job *job) {
439
454
swift_task_enqueueMainExecutorImpl (job);
440
455
}
441
456
442
- #if !SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
457
+ #if SWIFT_CONCURRENCY_ENABLE_DISPATCH
443
458
void swift::swift_task_enqueueOnDispatchQueue (Job *job,
444
459
HeapObject *_queue) {
445
460
JobPriority priority = job->getPriority ();
@@ -449,7 +464,8 @@ void swift::swift_task_enqueueOnDispatchQueue(Job *job,
449
464
#endif
450
465
451
466
ExecutorRef 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
453
469
return ExecutorRef::generic ();
454
470
#else
455
471
return ExecutorRef::forOrdinary (
@@ -459,7 +475,8 @@ ExecutorRef swift::swift_task_getMainExecutor() {
459
475
}
460
476
461
477
bool 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
463
480
return isGeneric ();
464
481
#else
465
482
return Identity == reinterpret_cast <HeapObject*>(&_dispatch_main_q);
0 commit comments