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