Skip to content

Commit 0e507f2

Browse files
authored
Revert "Allow building a concurrent libSwiftConcurrency without libdispatch"
1 parent f9b008e commit 0e507f2

File tree

7 files changed

+25
-70
lines changed

7 files changed

+25
-70
lines changed

include/swift/Runtime/Concurrency.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,6 @@
2525
#pragma clang diagnostic push
2626
#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
2727

28-
// Does the runtime use a cooperative global executor?
29-
#if defined(SWIFT_STDLIB_SINGLE_THREADED_RUNTIME)
30-
#define SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR 1
31-
#else
32-
#define SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR 0
33-
#endif
34-
35-
// Does the runtime integrate with libdispatch?
36-
#ifndef SWIFT_CONCURRENCY_ENABLE_DISPATCH
37-
#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
38-
#define SWIFT_CONCURRENCY_ENABLE_DISPATCH 0
39-
#else
40-
#define SWIFT_CONCURRENCY_ENABLE_DISPATCH 1
41-
#endif
42-
#endif
43-
4428
namespace swift {
4529
class DefaultActor;
4630
class TaskOptionRecord;
@@ -677,14 +661,10 @@ void swift_task_enqueueGlobalWithDelay(unsigned long long delay, Job *job);
677661
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
678662
void swift_task_enqueueMainExecutor(Job *job);
679663

680-
#if SWIFT_CONCURRENCY_ENABLE_DISPATCH
681-
682664
/// Enqueue the given job on the main executor.
683665
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
684666
void swift_task_enqueueOnDispatchQueue(Job *job, HeapObject *queue);
685667

686-
#endif
687-
688668
/// A hook to take over global enqueuing.
689669
typedef SWIFT_CC(swift) void (*swift_task_enqueueGlobal_original)(Job *job);
690670
SWIFT_EXPORT_FROM(swift_Concurrency)
@@ -826,17 +806,6 @@ void swift_task_reportUnexpectedExecutor(
826806
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
827807
JobPriority swift_task_getCurrentThreadPriority(void);
828808

829-
#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
830-
831-
/// Donate this thread to the global executor until either the
832-
/// given condition returns true or we've run out of cooperative
833-
/// tasks to run.
834-
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
835-
void swift_task_donateThreadToGlobalExecutorUntil(bool (*condition)(void*),
836-
void *context);
837-
838-
#endif
839-
840809
#ifdef __APPLE__
841810
/// A magic symbol whose address is the mask to apply to a frame pointer to
842811
/// signal that it is an async frame. Do not try to read the actual value of

stdlib/public/Concurrency/Actor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#include "TaskPrivate.h"
4747
#include "VoucherSupport.h"
4848

49-
#if SWIFT_CONCURRENCY_ENABLE_DISPATCH
49+
#if !SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
5050
#include <dispatch/dispatch.h>
5151
#endif
5252

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ endif()
3535
set(SWIFT_RUNTIME_CONCURRENCY_C_FLAGS)
3636
set(SWIFT_RUNTIME_CONCURRENCY_SWIFT_FLAGS)
3737

38-
if(NOT SWIFT_CONCURRENCY_USES_DISPATCH)
39-
list(APPEND SWIFT_RUNTIME_CONCURRENCY_C_FLAGS
40-
"-DSWIFT_CONCURRENCY_ENABLE_DISPATCH=0")
41-
endif()
42-
4338
if(NOT swift_concurrency_async_fp_mode)
4439
set(swift_concurrency_async_fp_mode "always")
4540
endif()

stdlib/public/Concurrency/GlobalExecutor.cpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#include "TaskPrivate.h"
6060
#include "Error.h"
6161

62-
#if SWIFT_CONCURRENCY_ENABLE_DISPATCH
62+
#if !SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
6363
#include <dispatch/dispatch.h>
6464

6565
#if !defined(_WIN32)
@@ -178,21 +178,15 @@ static Job *claimNextFromJobQueue() {
178178
}
179179
}
180180

181-
void swift::
182-
swift_task_donateThreadToGlobalExecutorUntil(bool (*condition)(void *),
183-
void *conditionContext) {
181+
void swift::donateThreadToGlobalExecutorUntil(bool (*condition)(void *),
182+
void *conditionContext) {
184183
while (!condition(conditionContext)) {
185184
auto job = claimNextFromJobQueue();
186185
if (!job) return;
187186
swift_job_run(job, ExecutorRef::generic());
188187
}
189188
}
190189

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-
196190
#else
197191

198192
// Ensure that Job's layout is compatible with what Dispatch expects.
@@ -336,9 +330,6 @@ static void swift_task_enqueueGlobalImpl(Job *job) {
336330

337331
#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
338332
insertIntoJobQueue(job);
339-
#elif !SWIFT_CONCURRENCY_ENABLE_DISPATCH
340-
swift_reportError(0, "operation unsupported without libdispatch: "
341-
"swift_task_enqueueGlobal");
342333
#else
343334
// We really want four things from the global execution service:
344335
// - Enqueuing work should have minimal runtime and memory overhead.
@@ -394,9 +385,6 @@ static void swift_task_enqueueGlobalWithDelayImpl(unsigned long long delay,
394385

395386
#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
396387
insertIntoDelayedJobQueue(delay, job);
397-
#elif !SWIFT_CONCURRENCY_ENABLE_DISPATCH
398-
swift_reportError(0, "operation unsupported without libdispatch: "
399-
"swift_task_enqueueGlobalWithDelay");
400388
#else
401389

402390
dispatch_function_t dispatchFunction = &__swift_run_job;
@@ -431,9 +419,6 @@ static void swift_task_enqueueMainExecutorImpl(Job *job) {
431419

432420
#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
433421
insertIntoJobQueue(job);
434-
#elif !SWIFT_CONCURRENCY_ENABLE_DISPATCH
435-
swift_reportError(0, "operation unsupported without libdispatch: "
436-
"swift_task_enqueueMainExecutor");
437422
#else
438423

439424
JobPriority priority = job->getPriority();
@@ -454,7 +439,7 @@ void swift::swift_task_enqueueMainExecutor(Job *job) {
454439
swift_task_enqueueMainExecutorImpl(job);
455440
}
456441

457-
#if SWIFT_CONCURRENCY_ENABLE_DISPATCH
442+
#if !SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
458443
void swift::swift_task_enqueueOnDispatchQueue(Job *job,
459444
HeapObject *_queue) {
460445
JobPriority priority = job->getPriority();
@@ -464,8 +449,7 @@ void swift::swift_task_enqueueOnDispatchQueue(Job *job,
464449
#endif
465450

466451
ExecutorRef swift::swift_task_getMainExecutor() {
467-
#if !SWIFT_CONCURRENCY_ENABLE_DISPATCH
468-
// FIXME: this isn't right for the non-cooperative environment
452+
#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
469453
return ExecutorRef::generic();
470454
#else
471455
return ExecutorRef::forOrdinary(
@@ -475,8 +459,7 @@ ExecutorRef swift::swift_task_getMainExecutor() {
475459
}
476460

477461
bool ExecutorRef::isMainExecutor() const {
478-
#if !SWIFT_CONCURRENCY_ENABLE_DISPATCH
479-
// FIXME: this isn't right for the non-cooperative environment
462+
#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
480463
return isGeneric();
481464
#else
482465
return Identity == reinterpret_cast<HeapObject*>(&_dispatch_main_q);

stdlib/public/Concurrency/Task.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "Debug.h"
2828
#include "Error.h"
2929

30-
#if SWIFT_CONCURRENCY_ENABLE_DISPATCH
30+
#if !SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
3131
#include <dispatch/dispatch.h>
3232
#endif
3333

@@ -248,7 +248,7 @@ static void destroyTask(SWIFT_CONTEXT HeapObject *obj) {
248248
}
249249

250250
static ExecutorRef executorForEnqueuedJob(Job *job) {
251-
#if !SWIFT_CONCURRENCY_ENABLE_DISPATCH
251+
#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
252252
return ExecutorRef::generic();
253253
#else
254254
void *jobQueue = job->SchedulerPrivate[Job::DispatchQueueIndex];
@@ -1065,19 +1065,13 @@ void swift::swift_continuation_logFailedCheck(const char *message) {
10651065
swift_reportError(0, message);
10661066
}
10671067

1068-
SWIFT_RUNTIME_ATTRIBUTE_NORETURN
10691068
SWIFT_CC(swift)
10701069
static void swift_task_asyncMainDrainQueueImpl() {
10711070
#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
10721071
bool Finished = false;
1073-
swift_task_donateThreadToGlobalExecutorUntil([](void *context) {
1072+
donateThreadToGlobalExecutorUntil([](void *context) {
10741073
return *reinterpret_cast<bool*>(context);
10751074
}, &Finished);
1076-
#elif !SWIFT_CONCURRENCY_ENABLE_DISPATCH
1077-
// FIXME: consider implementing a concurrent global main queue for
1078-
// these environments?
1079-
swift_reportError(0, "operation unsupported without libdispatch: "
1080-
"swift_task_asyncMainDrainQueue");
10811075
#else
10821076
#if defined(_WIN32)
10831077
static void(FAR *pfndispatch_main)(void) = NULL;

stdlib/public/Concurrency/TaskGroup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "queue" // TODO: remove and replace with usage of our mpsc queue
3535
#include <atomic>
3636
#include <assert.h>
37-
#if SWIFT_CONCURRENCY_ENABLE_DISPATCH
37+
#if !SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
3838
#include <dispatch/dispatch.h>
3939
#endif
4040

stdlib/public/Concurrency/TaskPrivate.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ void asyncLet_addImpl(AsyncTask *task, AsyncLet *asyncLet,
100100
/// Clear the active task reference for the current thread.
101101
AsyncTask *_swift_task_clearCurrent();
102102

103+
#if defined(SWIFT_STDLIB_SINGLE_THREADED_RUNTIME)
104+
#define SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR 1
105+
#else
106+
#define SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR 0
107+
#endif
108+
109+
#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
110+
/// Donate this thread to the global executor until either the
111+
/// given condition returns true or we've run out of cooperative
112+
/// tasks to run.
113+
void donateThreadToGlobalExecutorUntil(bool (*condition)(void*),
114+
void *context);
115+
#endif
116+
103117
/// release() establishes a happens-before relation with a preceding acquire()
104118
/// on the same address.
105119
void _swift_tsan_acquire(void *addr);

0 commit comments

Comments
 (0)