OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/edk/util/cond_var.h" | 5 #include "mojo/edk/util/cond_var.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include <thread> | 10 #include <thread> |
11 #include <type_traits> | 11 #include <type_traits> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "mojo/edk/system/test/sleep.h" | 14 #include "mojo/edk/platform/thread_utils.h" |
15 #include "mojo/edk/system/test/stopwatch.h" | 15 #include "mojo/edk/system/test/stopwatch.h" |
16 #include "mojo/edk/system/test/timeouts.h" | 16 #include "mojo/edk/system/test/timeouts.h" |
17 #include "mojo/edk/util/mutex.h" | 17 #include "mojo/edk/util/mutex.h" |
18 #include "mojo/public/cpp/system/macros.h" | 18 #include "mojo/public/cpp/system/macros.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
| 21 using mojo::platform::ThreadSleep; |
21 using mojo::system::test::DeadlineFromMilliseconds; | 22 using mojo::system::test::DeadlineFromMilliseconds; |
22 using mojo::system::test::EpsilonTimeout; | 23 using mojo::system::test::EpsilonTimeout; |
23 using mojo::system::test::SleepMilliseconds; | |
24 using mojo::system::test::Stopwatch; | 24 using mojo::system::test::Stopwatch; |
25 using mojo::system::test::TinyTimeout; | 25 using mojo::system::test::TinyTimeout; |
26 | 26 |
27 namespace mojo { | 27 namespace mojo { |
28 namespace util { | 28 namespace util { |
29 namespace { | 29 namespace { |
30 | 30 |
31 // Sleeps for a "very small" amount of time. | 31 // Sleeps for a "very small" amount of time. |
32 void EpsilonRandomSleep() { | 32 void EpsilonRandomSleep() { |
33 SleepMilliseconds(static_cast<unsigned>(rand()) % 20u); | 33 ThreadSleep(DeadlineFromMilliseconds(static_cast<unsigned>(rand()) % 20u)); |
34 } | 34 } |
35 | 35 |
36 // We'll use |MojoDeadline| with |uint64_t| (for |CondVar::WaitWithTimeout()|'s | 36 // We'll use |MojoDeadline| with |uint64_t| (for |CondVar::WaitWithTimeout()|'s |
37 // timeout argument), though note that |WaitWithTimeout()| doesn't support | 37 // timeout argument), though note that |WaitWithTimeout()| doesn't support |
38 // |MOJO_DEADLINE_INDEFINITE|. | 38 // |MOJO_DEADLINE_INDEFINITE|. |
39 static_assert(std::is_same<uint64_t, MojoDeadline>::value, | 39 static_assert(std::is_same<uint64_t, MojoDeadline>::value, |
40 "MojoDeadline isn't uint64_t!"); | 40 "MojoDeadline isn't uint64_t!"); |
41 | 41 |
42 TEST(CondVarTest, Basic) { | 42 TEST(CondVarTest, Basic) { |
43 // Create/destroy. | 43 // Create/destroy. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 // But we expect that it should time out soon after that amount of time. | 167 // But we expect that it should time out soon after that amount of time. |
168 EXPECT_LT(elapsed, timeout + EpsilonTimeout()); | 168 EXPECT_LT(elapsed, timeout + EpsilonTimeout()); |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 // TODO(vtl): Test that |Signal()| (usually) wakes only one waiter. | 172 // TODO(vtl): Test that |Signal()| (usually) wakes only one waiter. |
173 | 173 |
174 } // namespace | 174 } // namespace |
175 } // namespace util | 175 } // namespace util |
176 } // namespace mojo | 176 } // namespace mojo |
OLD | NEW |