Skip to content

Commit 855dd8d

Browse files
committed
[Tests] Use a plain array of std::atomic rather than a vector of atomic.
The restrictions on std::atomic make a it fragile to have a vector of them, and this failed to compile on Linux in CI. While I'm in there, clean up a couple of tests that repeated a raw `10` for the thread count. rdar://problem/49709062
1 parent e172c28 commit 855dd8d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

unittests/runtime/Mutex.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,12 @@ TEST(StaticReadWriteLockTest, ScopedWriteUnlockThreaded) {
555555
template <typename RW> void readLockWhileReadLockedThreaded(RW &lock) {
556556
lock.readLock();
557557

558-
std::vector<std::atomic<bool>> results(10);
558+
const int threadCount = 10;
559+
560+
std::atomic<bool> results[threadCount] = {};
559561

560562
std::atomic<bool> done(false);
561-
threadedExecute(10,
563+
threadedExecute(threadCount,
562564
[&](int index) {
563565
// Always perform at least one iteration of this loop to
564566
// avoid spurious failures if this thread is slow to run.
@@ -596,10 +598,12 @@ TEST(StaticReadWriteLockTest, ReadLockWhileReadLockedThreaded) {
596598
template <typename RW> void readLockWhileWriteLockedThreaded(RW &lock) {
597599
lock.writeLock();
598600

599-
std::vector<std::atomic<int>> results(10);
601+
const int threadCount = 10;
602+
603+
std::atomic<int> results[threadCount] = {};
600604

601605
std::atomic<bool> done(false);
602-
threadedExecute(10,
606+
threadedExecute(threadCount,
603607
[&](int index) {
604608
// Always perform at least one iteration of this loop to
605609
// avoid spurious failures if this thread is slow to run.
@@ -638,7 +642,7 @@ template <typename RW> void writeLockWhileReadLockedThreaded(RW &lock) {
638642

639643
const int threadCount = 10;
640644

641-
std::vector<std::atomic<int>> results(threadCount);
645+
std::atomic<int> results[threadCount] = {};
642646

643647
std::atomic<bool> done(false);
644648
threadedExecute(threadCount,
@@ -680,7 +684,7 @@ template <typename RW> void writeLockWhileWriteLockedThreaded(RW &lock) {
680684

681685
const int threadCount = 10;
682686

683-
std::vector<std::atomic<int>> results(threadCount);
687+
std::atomic<int> results[threadCount] = {};
684688

685689
std::atomic<bool> done(false);
686690
threadedExecute(threadCount,
@@ -753,7 +757,7 @@ template <typename RW> void tryReadLockWhileReadLockedThreaded(RW &lock) {
753757

754758
const int threadCount = 10;
755759

756-
std::vector<std::atomic<bool>> results(threadCount);
760+
std::atomic<bool> results[threadCount] = {};
757761

758762
std::atomic<bool> done(false);
759763
threadedExecute(threadCount,

0 commit comments

Comments
 (0)