OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/atomic_sequence_num.h" | 6 #include "base/atomic_sequence_num.h" |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/simple_thread.h" | 8 #include "base/simple_thread.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 static int constructed; | 35 static int constructed; |
36 private: | 36 private: |
37 int some_int_; | 37 int some_int_; |
38 }; | 38 }; |
39 | 39 |
40 int SlowConstructor::constructed = 0; | 40 int SlowConstructor::constructed = 0; |
41 | 41 |
42 class SlowDelegate : public base::DelegateSimpleThread::Delegate { | 42 class SlowDelegate : public base::DelegateSimpleThread::Delegate { |
43 public: | 43 public: |
44 SlowDelegate(base::LazyInstance<SlowConstructor>* lazy) : lazy_(lazy) { } | 44 explicit SlowDelegate(base::LazyInstance<SlowConstructor>* lazy) |
| 45 : lazy_(lazy) {} |
| 46 |
45 virtual void Run() { | 47 virtual void Run() { |
46 EXPECT_EQ(12, lazy_->Get().some_int()); | 48 EXPECT_EQ(12, lazy_->Get().some_int()); |
47 EXPECT_EQ(12, lazy_->Pointer()->some_int()); | 49 EXPECT_EQ(12, lazy_->Pointer()->some_int()); |
48 } | 50 } |
49 | 51 |
50 private: | 52 private: |
51 base::LazyInstance<SlowConstructor>* lazy_; | 53 base::LazyInstance<SlowConstructor>* lazy_; |
52 }; | 54 }; |
53 | 55 |
54 } // namespace | 56 } // namespace |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 88 |
87 base::DelegateSimpleThreadPool pool("lazy_instance_cons", 5); | 89 base::DelegateSimpleThreadPool pool("lazy_instance_cons", 5); |
88 pool.AddWork(&delegate, 20); | 90 pool.AddWork(&delegate, 20); |
89 EXPECT_EQ(0, SlowConstructor::constructed); | 91 EXPECT_EQ(0, SlowConstructor::constructed); |
90 | 92 |
91 pool.Start(); | 93 pool.Start(); |
92 pool.JoinAll(); | 94 pool.JoinAll(); |
93 EXPECT_EQ(1, SlowConstructor::constructed); | 95 EXPECT_EQ(1, SlowConstructor::constructed); |
94 } | 96 } |
95 } | 97 } |
OLD | NEW |