Skip to content

Commit cdb2418

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 cdb2418

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

unittests/Threading/ThreadingHelpers.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,37 @@
1313
#ifndef THREADING_HELPERS_H
1414
#define THREADING_HELPERS_H
1515

16+
#if SWIFT_THREADING_NONE
17+
18+
template <typename ThreadBody, typename AfterSpinRelease>
19+
void threadedExecute(int threadCount, ThreadBody threadBody,
20+
AfterSpinRelease afterSpinRelease) {
21+
for (int i = 0; i < threadCount; ++i) {
22+
threadBody(i);
23+
}
24+
}
25+
26+
template <typename ThreadBody>
27+
void threadedExecute(int threadCount, ThreadBody threadBody) {
28+
threadedExecute(threadCount, threadBody, [] {});
29+
}
30+
31+
template <typename M, typename C, typename ConsumerBody, typename ProducerBody>
32+
void threadedExecute(M &mutex, C &condition, bool &doneCondition,
33+
ConsumerBody consumerBody, ProducerBody producerBody) {
34+
for (int i = 1; i <= 5; ++i) {
35+
producerBody(i);
36+
}
37+
mutex.withLockThenNotifyAll(condition, [&] {
38+
doneCondition = true;
39+
});
40+
for (int i = 1; i <= 8; ++i) {
41+
consumerBody(i);
42+
}
43+
}
44+
45+
#else // !SWIFT_THREADING_NONE
46+
1647
#include <thread>
1748

1849
// When true many of the threaded tests log activity to help triage issues.
@@ -131,4 +162,6 @@ void threadedExecute(M &mutex, C &condition, bool &doneCondition,
131162
}
132163
}
133164

165+
#endif // !SWIFT_THREADING_NONE
166+
134167
#endif

0 commit comments

Comments
 (0)