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

Side by Side Diff: mojo/public/cpp/utility/tests/mutex_unittest.cc

Issue 668663006: Standardize usage of virtual/override/final in mojo/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/public/cpp/utility/mutex.h" 5 #include "mojo/public/cpp/utility/mutex.h"
6 6
7 #include <stdlib.h> // For |rand()|. 7 #include <stdlib.h> // For |rand()|.
8 #include <time.h> // For |nanosleep()| (defined by POSIX). 8 #include <time.h> // For |nanosleep()| (defined by POSIX).
9 9
10 #include <vector> 10 #include <vector>
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 MOJO_DISALLOW_COPY_AND_ASSIGN(Fiddler); 104 MOJO_DISALLOW_COPY_AND_ASSIGN(Fiddler);
105 }; 105 };
106 106
107 class FiddlerThread : public Thread { 107 class FiddlerThread : public Thread {
108 public: 108 public:
109 // Takes ownership of |fiddler|. 109 // Takes ownership of |fiddler|.
110 FiddlerThread(Fiddler* fiddler) 110 FiddlerThread(Fiddler* fiddler)
111 : fiddler_(fiddler) { 111 : fiddler_(fiddler) {
112 } 112 }
113 113
114 virtual ~FiddlerThread() { 114 ~FiddlerThread() override { delete fiddler_; }
115 delete fiddler_;
116 }
117 115
118 virtual void Run() override { fiddler_->Fiddle(); } 116 void Run() override { fiddler_->Fiddle(); }
119 117
120 private: 118 private:
121 Fiddler* const fiddler_; 119 Fiddler* const fiddler_;
122 120
123 MOJO_DISALLOW_COPY_AND_ASSIGN(FiddlerThread); 121 MOJO_DISALLOW_COPY_AND_ASSIGN(FiddlerThread);
124 }; 122 };
125 123
126 // This does a stress test (that also checks exclusion). 124 // This does a stress test (that also checks exclusion).
127 TEST(MutexTest, ThreadedStress) { 125 TEST(MutexTest, ThreadedStress) {
128 static const size_t kNumThreads = 20; 126 static const size_t kNumThreads = 20;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 158
161 // Delete. 159 // Delete.
162 for (size_t i = 0; i < kNumThreads; i++) 160 for (size_t i = 0; i < kNumThreads; i++)
163 delete fiddler_threads[i]; 161 delete fiddler_threads[i];
164 fiddler_threads.clear(); 162 fiddler_threads.clear();
165 } 163 }
166 164
167 class TryThread : public Thread { 165 class TryThread : public Thread {
168 public: 166 public:
169 explicit TryThread(Mutex* mutex) : mutex_(mutex), try_lock_succeeded_() {} 167 explicit TryThread(Mutex* mutex) : mutex_(mutex), try_lock_succeeded_() {}
170 virtual ~TryThread() {} 168 ~TryThread() override {}
171 169
172 virtual void Run() override { 170 void Run() override {
173 try_lock_succeeded_ = mutex_->TryLock(); 171 try_lock_succeeded_ = mutex_->TryLock();
174 if (try_lock_succeeded_) 172 if (try_lock_succeeded_)
175 mutex_->Unlock(); 173 mutex_->Unlock();
176 } 174 }
177 175
178 bool try_lock_succeeded() const { return try_lock_succeeded_; } 176 bool try_lock_succeeded() const { return try_lock_succeeded_; }
179 177
180 private: 178 private:
181 Mutex* const mutex_; 179 Mutex* const mutex_;
182 bool try_lock_succeeded_; 180 bool try_lock_succeeded_;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 // Destroy lock with lock held. 250 // Destroy lock with lock held.
253 EXPECT_DEATH_IF_SUPPORTED({ 251 EXPECT_DEATH_IF_SUPPORTED({
254 Mutex mutex; 252 Mutex mutex;
255 mutex.Lock(); 253 mutex.Lock();
256 }, ""); 254 }, "");
257 } 255 }
258 #endif // !defined(NDEBUG) 256 #endif // !defined(NDEBUG)
259 257
260 } // namespace 258 } // namespace
261 } // namespace mojo 259 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/system/tests/macros_unittest.cc ('k') | mojo/public/cpp/utility/tests/run_loop_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698