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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 void ScheduleWork(MessageLoop::Type target_type, int num_scheduling_threads) { | 63 void ScheduleWork(MessageLoop::Type target_type, int num_scheduling_threads) { |
64 #if defined(OS_ANDROID) | 64 #if defined(OS_ANDROID) |
65 if (target_type == MessageLoop::TYPE_JAVA) { | 65 if (target_type == MessageLoop::TYPE_JAVA) { |
66 java_thread_.reset(new android::JavaHandlerThread("target")); | 66 java_thread_.reset(new android::JavaHandlerThread("target")); |
67 java_thread_->Start(); | 67 java_thread_->Start(); |
68 } else | 68 } else |
69 #endif | 69 #endif |
70 { | 70 { |
71 target_.reset(new Thread("target")); | 71 target_.reset(new Thread("target")); |
72 target_->StartWithOptions(Thread::Options(target_type, 0u)); | 72 target_->StartWithOptions(Thread::Options(target_type, 0u)); |
| 73 |
| 74 // Without this, it's possible for the scheduling threads to start and run |
| 75 // before the target thread. In this case, the scheduling threads will |
| 76 // call target_message_loop()->ScheduleWork(), which dereferences the |
| 77 // loop's message pump, which is only created after the target thread has |
| 78 // finished starting. |
| 79 target_->WaitUntilThreadStarted(); |
73 } | 80 } |
74 | 81 |
75 ScopedVector<Thread> scheduling_threads; | 82 ScopedVector<Thread> scheduling_threads; |
76 scheduling_times_.reset(new base::TimeDelta[num_scheduling_threads]); | 83 scheduling_times_.reset(new base::TimeDelta[num_scheduling_threads]); |
77 scheduling_thread_times_.reset(new base::TimeDelta[num_scheduling_threads]); | 84 scheduling_thread_times_.reset(new base::TimeDelta[num_scheduling_threads]); |
78 min_batch_times_.reset(new base::TimeDelta[num_scheduling_threads]); | 85 min_batch_times_.reset(new base::TimeDelta[num_scheduling_threads]); |
79 max_batch_times_.reset(new base::TimeDelta[num_scheduling_threads]); | 86 max_batch_times_.reset(new base::TimeDelta[num_scheduling_threads]); |
80 | 87 |
81 for (int i = 0; i < num_scheduling_threads; ++i) { | 88 for (int i = 0; i < num_scheduling_threads; ++i) { |
82 scheduling_threads.push_back(new Thread("posting thread")); | 89 scheduling_threads.push_back(new Thread("posting thread")); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 286 |
280 TEST_F(PostTaskTest, TenTasksPerReload) { | 287 TEST_F(PostTaskTest, TenTasksPerReload) { |
281 Run(10000, 10); | 288 Run(10000, 10); |
282 } | 289 } |
283 | 290 |
284 TEST_F(PostTaskTest, OneHundredTasksPerReload) { | 291 TEST_F(PostTaskTest, OneHundredTasksPerReload) { |
285 Run(1000, 100); | 292 Run(1000, 100); |
286 } | 293 } |
287 | 294 |
288 } // namespace base | 295 } // namespace base |
OLD | NEW |