1 //===-- condition_variable_test.cpp -----------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "tests/scudo_unit_test.h"
12 #include "condition_variable.h"
17 template <typename ConditionVariableT
> void simpleWaitAndNotifyAll() {
18 constexpr scudo::u32 NumThreads
= 2;
19 constexpr scudo::u32 CounterMax
= 1024;
20 std::thread Threads
[NumThreads
];
23 ConditionVariableT CV
;
25 scudo::u32 Counter
= 0;
27 for (scudo::u32 I
= 0; I
< NumThreads
; ++I
) {
28 Threads
[I
] = std::thread(
31 scudo::ScopedLock
L(M
);
32 if (Counter
% NumThreads
!= Id
&& Counter
< CounterMax
)
34 if (Counter
>= CounterMax
) {
45 for (std::thread
&T
: Threads
)
48 EXPECT_EQ(Counter
, CounterMax
);
51 TEST(ScudoConditionVariableTest
, DummyCVWaitAndNotifyAll
) {
52 simpleWaitAndNotifyAll
<scudo::ConditionVariableDummy
>();
56 TEST(ScudoConditionVariableTest
, LinuxCVWaitAndNotifyAll
) {
57 simpleWaitAndNotifyAll
<scudo::ConditionVariableLinux
>();