Skip to content

Commit e9d1d30

Browse files
authored
Stop using SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY under SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY (#62735)
Using single-threaded concurrency was a temporary solution, now that the task-to-thread model actually supports multiple threads, let's switch off of it. Instead, let's introduce a "global executor none" option (implicitly set under the task-to-thread model) to denote that the concurrency model is not using a global executor. rdar://99448771
1 parent f407389 commit e9d1d30

File tree

8 files changed

+30
-5
lines changed

8 files changed

+30
-5
lines changed

include/swift/Runtime/DispatchShims.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#if SWIFT_CONCURRENCY_ENABLE_PRIORITY_ESCALATION
1919
#include <dispatch/swift_concurrency_private.h>
2020

21+
#if SWIFT_CONCURRENCY_TASK_TO_THREAD_MODEL
22+
#error Cannot use task-to-thread model with priority escalation
23+
#endif
24+
2125
// Provide wrappers with runtime checks to make sure that the dispatch functions
2226
// are only called on OS-es where they are supported
2327
static inline dispatch_thread_override_info_s

include/swift/Runtime/VoucherShims.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040

4141
#if SWIFT_HAS_VOUCHERS
4242

43+
#if SWIFT_CONCURRENCY_TASK_TO_THREAD_MODEL
44+
#error Cannot use task-to-thread model with vouchers
45+
#endif
46+
4347
#if SWIFT_HAS_VOUCHER_HEADER
4448

4549
#else

stdlib/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,19 @@ if("${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "singlethreaded"
180180
message(SEND_ERROR "Cannot enable the single-threaded global executor without enabling SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY")
181181
endif()
182182

183+
if(SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY)
184+
if(SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY)
185+
message(SEND_ERROR "Cannot use the single-threaded concurrency with task-to-thread concurrency model")
186+
endif()
187+
if(NOT "${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "none")
188+
message(SEND_ERROR "Task-to-thread concurrency model requires no global executor")
189+
endif()
190+
else()
191+
if("${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "none")
192+
message(SEND_ERROR "Only task-to-thread concurrency model is usable with no global executor")
193+
endif()
194+
endif()
195+
183196
swift_create_stdlib_targets("swift-stdlib" "" TRUE)
184197
if(SWIFT_STDLIB_ENABLE_SIB_TARGETS)
185198
swift_create_stdlib_targets("swift-stdlib" "sib" TRUE)

stdlib/cmake/modules/StdlibOptions.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,17 @@ option(SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY
197197
"Build the standard libraries assuming that they will be used in an environment with only a single thread."
198198
FALSE)
199199

200-
if(SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY)
200+
if(SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY)
201+
set(SWIFT_CONCURRENCY_GLOBAL_EXECUTOR_default "none")
202+
elseif(SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY)
201203
set(SWIFT_CONCURRENCY_GLOBAL_EXECUTOR_default "singlethreaded")
202204
else()
203205
set(SWIFT_CONCURRENCY_GLOBAL_EXECUTOR_default "dispatch")
204206
endif()
205207

206208
set(SWIFT_CONCURRENCY_GLOBAL_EXECUTOR
207209
"${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR_default}" CACHE STRING
208-
"Build the concurrency library to use the given global executor (options: dispatch, singlethreaded, hooked)")
210+
"Build the concurrency library to use the given global executor (options: none, dispatch, singlethreaded, hooked)")
209211

210212
option(SWIFT_STDLIB_OS_VERSIONING
211213
"Build stdlib with availability based on OS versions (Darwin only)."

stdlib/public/Concurrency/Actor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ static bool isExecutingOnMainThread() {
283283
JobPriority swift::swift_task_getCurrentThreadPriority() {
284284
#if SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY
285285
return JobPriority::UserInitiated;
286+
#elif SWIFT_CONCURRENCY_TASK_TO_THREAD_MODEL
287+
return JobPriority::Unspecified;
286288
#elif defined(__APPLE__)
287289
return static_cast<JobPriority>(qos_class_self());
288290
#else

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ if("${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "dispatch")
4444
dispatch)
4545
endif()
4646
elseif("${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "singlethreaded" OR
47-
"${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "hooked")
47+
"${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "hooked" OR
48+
"${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "none")
4849
list(APPEND SWIFT_RUNTIME_CONCURRENCY_C_FLAGS
4950
"-DSWIFT_CONCURRENCY_ENABLE_DISPATCH=0")
5051
else()

test/Concurrency/Runtime/cancellation_handler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// rdar://76038845
66
// REQUIRES: concurrency_runtime
77
// UNSUPPORTED: back_deployment_runtime
8-
// UNSUPPORTED: single_threaded_concurrency
8+
// UNSUPPORTED: freestanding
99

1010
// for sleep
1111
#if canImport(Darwin)

utils/build-presets.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2544,7 +2544,6 @@ swift-stdlib-has-stdin=0
25442544
swift-stdlib-has-environ=0
25452545
swift-stdlib-has-locale=0
25462546
swift-runtime-static-image-inspection=1
2547-
swift-stdlib-single-threaded-concurrency=1
25482547
swift-stdlib-concurrency-tracing=0
25492548
swift-stdlib-os-versioning=0
25502549
swift-stdlib-has-commandline=0

0 commit comments

Comments
 (0)