| 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 explicit SlowDelegate(base::LazyInstance<SlowConstructor>* lazy) | 44 SlowDelegate(base::LazyInstance<SlowConstructor>* lazy) : lazy_(lazy) { } |
| 45 : lazy_(lazy) {} | |
| 46 | |
| 47 virtual void Run() { | 45 virtual void Run() { |
| 48 EXPECT_EQ(12, lazy_->Get().some_int()); | 46 EXPECT_EQ(12, lazy_->Get().some_int()); |
| 49 EXPECT_EQ(12, lazy_->Pointer()->some_int()); | 47 EXPECT_EQ(12, lazy_->Pointer()->some_int()); |
| 50 } | 48 } |
| 51 | 49 |
| 52 private: | 50 private: |
| 53 base::LazyInstance<SlowConstructor>* lazy_; | 51 base::LazyInstance<SlowConstructor>* lazy_; |
| 54 }; | 52 }; |
| 55 | 53 |
| 56 } // namespace | 54 } // namespace |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 86 |
| 89 base::DelegateSimpleThreadPool pool("lazy_instance_cons", 5); | 87 base::DelegateSimpleThreadPool pool("lazy_instance_cons", 5); |
| 90 pool.AddWork(&delegate, 20); | 88 pool.AddWork(&delegate, 20); |
| 91 EXPECT_EQ(0, SlowConstructor::constructed); | 89 EXPECT_EQ(0, SlowConstructor::constructed); |
| 92 | 90 |
| 93 pool.Start(); | 91 pool.Start(); |
| 94 pool.JoinAll(); | 92 pool.JoinAll(); |
| 95 EXPECT_EQ(1, SlowConstructor::constructed); | 93 EXPECT_EQ(1, SlowConstructor::constructed); |
| 96 } | 94 } |
| 97 } | 95 } |
| OLD | NEW |