Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: mojo/edk/util/mutex_unittest.cc

Issue 1408003013: Reland "EDK: Move //mojo/edk/system/waitable_event* to edk/util." (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/util/cond_var_unittest.cc ('k') | mojo/edk/util/ref_counted_perftest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/mutex.h" 5 #include "mojo/edk/util/mutex.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <thread> 9 #include <thread>
10 10
11 #include "mojo/edk/system/test/sleep.h" 11 #include "mojo/edk/system/test/sleep.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 using mojo::system::test::SleepMilliseconds;
15
14 namespace mojo { 16 namespace mojo {
15 namespace util { 17 namespace util {
16 namespace { 18 namespace {
17 19
18 // Sleeps for a "very small" amount of time. 20 // Sleeps for a "very small" amount of time.
19 void EpsilonRandomSleep() { 21 void EpsilonRandomSleep() {
20 system::test::SleepMilliseconds(static_cast<unsigned>(rand()) % 20u); 22 SleepMilliseconds(static_cast<unsigned>(rand()) % 20u);
21 } 23 }
22 24
23 // Basic test to make sure that Lock()/Unlock()/TryLock() don't crash ---------- 25 // Basic test to make sure that Lock()/Unlock()/TryLock() don't crash ----------
24 26
25 TEST(MutexTest, Basic) { 27 TEST(MutexTest, Basic) {
26 Mutex mutex; 28 Mutex mutex;
27 29
28 int thread_acquired = 0; 30 int thread_acquired = 0;
29 auto thread = std::thread([&mutex, &thread_acquired]() { 31 auto thread = std::thread([&mutex, &thread_acquired]() {
30 for (int i = 0; i < 10; i++) { 32 for (int i = 0; i < 10; i++) {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 194
193 // The destruction of |locker| should unlock |mutex|. 195 // The destruction of |locker| should unlock |mutex|.
194 ASSERT_TRUE(mutex.TryLock()); 196 ASSERT_TRUE(mutex.TryLock());
195 mutex.AssertHeld(); 197 mutex.AssertHeld();
196 mutex.Unlock(); 198 mutex.Unlock();
197 } 199 }
198 200
199 } // namespace 201 } // namespace
200 } // namespace util 202 } // namespace util
201 } // namespace mojo 203 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/util/cond_var_unittest.cc ('k') | mojo/edk/util/ref_counted_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698