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

Side by Side Diff: base/simple_thread_unittest.cc

Issue 552004: Style cleanup in preparation for auto-linting base/. (Closed)
Patch Set: Created 10 years, 11 months 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 | « base/sha2.h ('k') | base/spin_wait.h » ('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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/atomic_sequence_num.h" 5 #include "base/atomic_sequence_num.h"
6 #include "base/lock.h" 6 #include "base/lock.h"
7 #include "base/simple_thread.h" 7 #include "base/simple_thread.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/waitable_event.h" 9 #include "base/waitable_event.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace { 12 namespace {
13 13
14 class SetIntRunner : public base::DelegateSimpleThread::Delegate { 14 class SetIntRunner : public base::DelegateSimpleThread::Delegate {
15 public: 15 public:
16 SetIntRunner(int* ptr, int val) : ptr_(ptr), val_(val) { } 16 SetIntRunner(int* ptr, int val) : ptr_(ptr), val_(val) { }
17 ~SetIntRunner() { } 17 ~SetIntRunner() { }
18 18
19 virtual void Run() { 19 virtual void Run() {
20 *ptr_ = val_; 20 *ptr_ = val_;
21 } 21 }
22 22
23 private: 23 private:
24 int* ptr_; 24 int* ptr_;
25 int val_; 25 int val_;
26 }; 26 };
27 27
28 class WaitEventRunner : public base::DelegateSimpleThread::Delegate { 28 class WaitEventRunner : public base::DelegateSimpleThread::Delegate {
29 public: 29 public:
30 WaitEventRunner(base::WaitableEvent* event) : event_(event) { } 30 explicit WaitEventRunner(base::WaitableEvent* event) : event_(event) { }
31 ~WaitEventRunner() { } 31 ~WaitEventRunner() { }
32 32
33 virtual void Run() { 33 virtual void Run() {
34 EXPECT_FALSE(event_->IsSignaled()); 34 EXPECT_FALSE(event_->IsSignaled());
35 event_->Signal(); 35 event_->Signal();
36 EXPECT_TRUE(event_->IsSignaled()); 36 EXPECT_TRUE(event_->IsSignaled());
37 } 37 }
38 private: 38 private:
39 base::WaitableEvent* event_; 39 base::WaitableEvent* event_;
40 }; 40 };
41 41
42 class SeqRunner : public base::DelegateSimpleThread::Delegate { 42 class SeqRunner : public base::DelegateSimpleThread::Delegate {
43 public: 43 public:
44 SeqRunner(base::AtomicSequenceNumber* seq) : seq_(seq) { } 44 explicit SeqRunner(base::AtomicSequenceNumber* seq) : seq_(seq) { }
45 virtual void Run() { 45 virtual void Run() {
46 seq_->GetNext(); 46 seq_->GetNext();
47 } 47 }
48 48
49 private: 49 private:
50 base::AtomicSequenceNumber* seq_; 50 base::AtomicSequenceNumber* seq_;
51 }; 51 };
52 52
53 // We count up on a sequence number, firing on the event when we've hit our 53 // We count up on a sequence number, firing on the event when we've hit our
54 // expected amount, otherwise we wait on the event. This will ensure that we 54 // expected amount, otherwise we wait on the event. This will ensure that we
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 base::WaitableEvent event(true, false); 158 base::WaitableEvent event(true, false);
159 // Changing 9 to 10, for example, would cause us JoinAll() to never return. 159 // Changing 9 to 10, for example, would cause us JoinAll() to never return.
160 VerifyPoolRunner verifier(&seq2, 9, &event); 160 VerifyPoolRunner verifier(&seq2, 9, &event);
161 pool.Start(); 161 pool.Start();
162 162
163 pool.AddWork(&verifier, 10); 163 pool.AddWork(&verifier, 10);
164 164
165 pool.JoinAll(); 165 pool.JoinAll();
166 EXPECT_EQ(seq2.GetNext(), 10); 166 EXPECT_EQ(seq2.GetNext(), 10);
167 } 167 }
OLDNEW
« no previous file with comments | « base/sha2.h ('k') | base/spin_wait.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698