Skip to content

Commit 11347a0

Browse files
authored
Merge pull request #3606 from swiftwasm/maxd/5.5-cooperative-executor
5.5 release: fix cooperative global executor
2 parents 8e48f7e + 7a5f534 commit 11347a0

File tree

11 files changed

+27
-8
lines changed

11 files changed

+27
-8
lines changed

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ function(add_swift_unittest test_dirname)
6565
_ENABLE_EXTENDED_ALIGNED_STORAGE)
6666
endif()
6767

68+
# some headers switch their inline implementations based on
69+
# SWIFT_STDLIB_SINGLE_THREADED_RUNTIME definition
70+
if(SWIFT_STDLIB_SINGLE_THREADED_RUNTIME)
71+
target_compile_definitions("${test_dirname}" PRIVATE
72+
SWIFT_STDLIB_SINGLE_THREADED_RUNTIME)
73+
endif()
74+
6875
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
6976
if(SWIFT_USE_LINKER)
7077
target_link_options(${test_dirname} PRIVATE

stdlib/public/Concurrency/GlobalExecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static DelayedJob *DelayedJobQueue = nullptr;
102102

103103
/// Get the next-in-queue storage slot.
104104
static Job *&nextInQueue(Job *cur) {
105-
return reinterpret_cast<Job*&>(cur->SchedulerPrivate);
105+
return reinterpret_cast<Job*&>(cur->SchedulerPrivate[Job::NextWaitingTaskIndex]);
106106
}
107107

108108
/// Insert a job into the cooperative global queue.

stdlib/public/Concurrency/Mutex.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "../runtime/MutexPThread.cpp"
1717
#include "../runtime/MutexWin32.cpp"
18-
1918
#ifdef SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
2019
#include "swift/Runtime/MutexSingleThreaded.h"
2120
#endif

test/Concurrency/Runtime/async_task_locals_copy_to_sync.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// rdar://76038845
88
// REQUIRES: concurrency_runtime
99
// UNSUPPORTED: back_deployment_runtime
10+
// Disable on cooperative executor because it can't dispatch jobs before the end of main function
11+
// UNSUPPORTED: single_threaded_runtime
1012

1113
import Dispatch
1214

test/Concurrency/Runtime/cancellation_handler.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
// rdar://76038845
66
// REQUIRES: concurrency_runtime
77
// UNSUPPORTED: back_deployment_runtime
8-
// UNSUPPORTED: OS=windows-msvc
9-
// UNSUPPORTED: OS=wasi
8+
// UNSUPPORTED: single_threaded_runtime
109

1110
// for sleep
1211
#if canImport(Darwin)

test/Concurrency/Runtime/data_race_detection.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// rdar://76038845
99
// REQUIRES: concurrency_runtime
1010
// UNSUPPORTED: back_deployment_runtime
11+
// UNSUPPORTED: single_threaded_runtime
12+
1113
import _Concurrency
1214
import Dispatch
1315

@@ -57,14 +59,14 @@ actor MyActor {
5759
struct Runner {
5860
static func main() async {
5961
print("Launching a main-actor task")
60-
// CHECK: warning: data race detected: @MainActor function at main/data_race_detection.swift:21 was not called on the main thread
62+
// CHECK: warning: data race detected: @MainActor function at main/data_race_detection.swift:23 was not called on the main thread
6163
launchFromMainThread()
6264
sleep(1)
6365

6466
let actor = MyActor()
6567
let actorFn = await actor.getTaskOnMyActor()
6668
print("Launching an actor-instance task")
67-
// CHECK: warning: data race detected: actor-isolated function at main/data_race_detection.swift:50 was not called on the same actor
69+
// CHECK: warning: data race detected: actor-isolated function at main/data_race_detection.swift:52 was not called on the same actor
6870
launchTask(actorFn)
6971

7072
sleep(1)

test/Concurrency/Runtime/mainactor.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// rdar://76038845
88
// REQUIRES: concurrency_runtime
99
// UNSUPPORTED: back_deployment_runtime
10+
// UNSUPPORTED: single_threaded_runtime
1011

1112
import Dispatch
1213

test/Interpreter/enforce_exclusive_access.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// RUN: %target-codesign %t/a.out
55
// RUN: %target-run %t/a.out
66
// REQUIRES: executable_test
7+
// UNSUPPORTED: single_threaded_runtime
78

89
// Tests for traps at run time when enforcing exclusive access.
910

unittests/runtime/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,24 @@ if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND
8484
endif()
8585
endif()
8686

87+
if(NOT SWIFT_STDLIB_SINGLE_THREADED_RUNTIME)
88+
list(APPEND PLATFORM_SOURCES Mutex.cpp)
89+
endif()
90+
8791
# Don't complain about these files not being in the sources list.
8892
set(LLVM_OPTIONAL_SOURCES
8993
weak.mm
9094
Refcounting.mm
9195
Actor.cpp
92-
TaskStatus.cpp)
96+
TaskStatus.cpp
97+
Mutex.cpp)
9398

9499
add_swift_unittest(SwiftRuntimeTests
95100
Array.cpp
96101
CompatibilityOverrideRuntime.cpp
97102
CompatibilityOverrideConcurrency.cpp
98103
Concurrent.cpp
99104
Metadata.cpp
100-
Mutex.cpp
101105
Enum.cpp
102106
Refcounting.cpp
103107
Stdlib.cpp

unittests/runtime/Concurrent.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ TEST(ConcurrentReadableArrayTest, SingleThreaded) {
4545
check();
4646
}
4747

48+
#ifndef SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
49+
4850
TEST(ConcurrentReadableArrayTest, MultiThreaded) {
4951
const int insertCount = 100000;
5052

@@ -542,3 +544,4 @@ TEST(ConcurrentReadableHashMapTest, MultiThreaded4) {
542544
runTest(16, 1);
543545
runTest(16, 8);
544546
}
547+
#endif // !SWIFT_STDLIB_SINGLE_THREADED_RUNTIME

0 commit comments

Comments
 (0)