OLD | NEW |
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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/format_macros.h" | 6 #include "base/format_macros.h" |
7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/synchronization/condition_variable.h" | 9 #include "base/synchronization/condition_variable.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 target_->StartWithOptions(Thread::Options(target_type, 0u)); | 77 target_->StartWithOptions(Thread::Options(target_type, 0u)); |
78 | 78 |
79 // Without this, it's possible for the scheduling threads to start and run | 79 // Without this, it's possible for the scheduling threads to start and run |
80 // before the target thread. In this case, the scheduling threads will | 80 // before the target thread. In this case, the scheduling threads will |
81 // call target_message_loop()->ScheduleWork(), which dereferences the | 81 // call target_message_loop()->ScheduleWork(), which dereferences the |
82 // loop's message pump, which is only created after the target thread has | 82 // loop's message pump, which is only created after the target thread has |
83 // finished starting. | 83 // finished starting. |
84 target_->WaitUntilThreadStarted(); | 84 target_->WaitUntilThreadStarted(); |
85 } | 85 } |
86 | 86 |
87 ScopedVector<Thread> scheduling_threads; | 87 std::vector<scoped_ptr<Thread>> scheduling_threads; |
88 scheduling_times_.reset(new base::TimeDelta[num_scheduling_threads]); | 88 scheduling_times_.reset(new base::TimeDelta[num_scheduling_threads]); |
89 scheduling_thread_times_.reset(new base::TimeDelta[num_scheduling_threads]); | 89 scheduling_thread_times_.reset(new base::TimeDelta[num_scheduling_threads]); |
90 min_batch_times_.reset(new base::TimeDelta[num_scheduling_threads]); | 90 min_batch_times_.reset(new base::TimeDelta[num_scheduling_threads]); |
91 max_batch_times_.reset(new base::TimeDelta[num_scheduling_threads]); | 91 max_batch_times_.reset(new base::TimeDelta[num_scheduling_threads]); |
92 | 92 |
93 for (int i = 0; i < num_scheduling_threads; ++i) { | 93 for (int i = 0; i < num_scheduling_threads; ++i) { |
94 scheduling_threads.push_back(new Thread("posting thread")); | 94 scheduling_threads.push_back( |
| 95 make_scoped_ptr(new Thread("posting thread"))); |
95 scheduling_threads[i]->Start(); | 96 scheduling_threads[i]->Start(); |
96 } | 97 } |
97 | 98 |
98 for (int i = 0; i < num_scheduling_threads; ++i) { | 99 for (int i = 0; i < num_scheduling_threads; ++i) { |
99 scheduling_threads[i]->message_loop()->PostTask( | 100 scheduling_threads[i]->message_loop()->PostTask( |
100 FROM_HERE, | 101 FROM_HERE, |
101 base::Bind(&ScheduleWorkTest::Schedule, base::Unretained(this), i)); | 102 base::Bind(&ScheduleWorkTest::Schedule, base::Unretained(this), i)); |
102 } | 103 } |
103 | 104 |
104 for (int i = 0; i < num_scheduling_threads; ++i) { | 105 for (int i = 0; i < num_scheduling_threads; ++i) { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 292 |
292 TEST_F(PostTaskTest, TenTasksPerReload) { | 293 TEST_F(PostTaskTest, TenTasksPerReload) { |
293 Run(10000, 10); | 294 Run(10000, 10); |
294 } | 295 } |
295 | 296 |
296 TEST_F(PostTaskTest, OneHundredTasksPerReload) { | 297 TEST_F(PostTaskTest, OneHundredTasksPerReload) { |
297 Run(1000, 100); | 298 Run(1000, 100); |
298 } | 299 } |
299 | 300 |
300 } // namespace base | 301 } // namespace base |
OLD | NEW |