Skip to content

Commit db312c4

Browse files
committed
[Threading][UnitTests] Don't use threads in the unit test in no-threads mode.
If the threading package is set to "none", don't actually use threads in the unit tests. rdar://95011060
1 parent 1062625 commit db312c4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

unittests/Threading/ThreadingHelpers.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,32 @@
1515

1616
#include <thread>
1717

18+
#if SWIFT_THREADING_NONE
19+
20+
template <typename ThreadBody, typename AfterSpinRelease>
21+
void threadedExecute(int threadCount, ThreadBody threadBody,
22+
AfterSpinRelease afterSpinRelease) {
23+
for (int i = 0; i < threadCount; ++i) {
24+
threadBody(i);
25+
}
26+
}
27+
28+
template <typename M, typename C, typename ConsumerBody, typename ProducerBody>
29+
void threadedExecute(M &mutex, C &condition, bool &doneCondition,
30+
ConsumerBody consumerBody, ProducerBody producerBody) {
31+
for (int i = 1; i <= 5; ++i) {
32+
producerBody(i);
33+
}
34+
mutex.withLockThenNotifyAll(condition, [&] {
35+
doneCondition = true;
36+
});
37+
for (int i = 1; i <= 8; ++i) {
38+
consumerBody(i);
39+
}
40+
}
41+
42+
#else // !SWIFT_THREADING_NONE
43+
1844
// When true many of the threaded tests log activity to help triage issues.
1945
static bool trace = false;
2046

@@ -131,4 +157,6 @@ void threadedExecute(M &mutex, C &condition, bool &doneCondition,
131157
}
132158
}
133159

160+
#endif // !SWIFT_THREADING_NONE
161+
134162
#endif

0 commit comments

Comments
 (0)