From cdb2418cb50d8febbf5f6ea6df4aeb5826b3a7a1 Mon Sep 17 00:00:00 2001 From: Alastair Houghton Date: Mon, 13 Jun 2022 12:50:36 +0100 Subject: [PATCH] [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 --- unittests/Threading/ThreadingHelpers.h | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/unittests/Threading/ThreadingHelpers.h b/unittests/Threading/ThreadingHelpers.h index 08e0e2d9a227f..1562ddbf35e60 100644 --- a/unittests/Threading/ThreadingHelpers.h +++ b/unittests/Threading/ThreadingHelpers.h @@ -13,6 +13,37 @@ #ifndef THREADING_HELPERS_H #define THREADING_HELPERS_H +#if SWIFT_THREADING_NONE + +template +void threadedExecute(int threadCount, ThreadBody threadBody, + AfterSpinRelease afterSpinRelease) { + for (int i = 0; i < threadCount; ++i) { + threadBody(i); + } +} + +template +void threadedExecute(int threadCount, ThreadBody threadBody) { + threadedExecute(threadCount, threadBody, [] {}); +} + +template +void threadedExecute(M &mutex, C &condition, bool &doneCondition, + ConsumerBody consumerBody, ProducerBody producerBody) { + for (int i = 1; i <= 5; ++i) { + producerBody(i); + } + mutex.withLockThenNotifyAll(condition, [&] { + doneCondition = true; + }); + for (int i = 1; i <= 8; ++i) { + consumerBody(i); + } +} + +#else // !SWIFT_THREADING_NONE + #include // 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, } } +#endif // !SWIFT_THREADING_NONE + #endif