| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Multi-threaded tests of ConditionVariable class. | 5 // Multi-threaded tests of ConditionVariable class. |
| 6 | 6 |
| 7 #include "base/synchronization/condition_variable.h" |
| 8 |
| 7 #include <time.h> | 9 #include <time.h> |
| 10 |
| 8 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <memory> |
| 9 #include <vector> | 13 #include <vector> |
| 10 | 14 |
| 11 #include "base/bind.h" | 15 #include "base/bind.h" |
| 12 #include "base/location.h" | 16 #include "base/location.h" |
| 13 #include "base/logging.h" | 17 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 16 #include "base/synchronization/condition_variable.h" | |
| 17 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 18 #include "base/synchronization/spin_wait.h" | 20 #include "base/synchronization/spin_wait.h" |
| 19 #include "base/threading/platform_thread.h" | 21 #include "base/threading/platform_thread.h" |
| 20 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 21 #include "base/threading/thread_collision_warner.h" | 23 #include "base/threading/thread_collision_warner.h" |
| 22 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| 23 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "testing/platform_test.h" | 27 #include "testing/platform_test.h" |
| 26 | 28 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // Both worker threads and controller use the following to synchronize. | 128 // Both worker threads and controller use the following to synchronize. |
| 127 Lock lock_; | 129 Lock lock_; |
| 128 ConditionVariable work_is_available_; // To tell threads there is work. | 130 ConditionVariable work_is_available_; // To tell threads there is work. |
| 129 | 131 |
| 130 // Conditions to notify the controlling process (if it is interested). | 132 // Conditions to notify the controlling process (if it is interested). |
| 131 ConditionVariable all_threads_have_ids_; // All threads are running. | 133 ConditionVariable all_threads_have_ids_; // All threads are running. |
| 132 ConditionVariable no_more_tasks_; // Task count is zero. | 134 ConditionVariable no_more_tasks_; // Task count is zero. |
| 133 | 135 |
| 134 const int thread_count_; | 136 const int thread_count_; |
| 135 int waiting_thread_count_; | 137 int waiting_thread_count_; |
| 136 scoped_ptr<PlatformThreadHandle[]> thread_handles_; | 138 std::unique_ptr<PlatformThreadHandle[]> thread_handles_; |
| 137 std::vector<int> assignment_history_; // Number of assignment per worker. | 139 std::vector<int> assignment_history_; // Number of assignment per worker. |
| 138 std::vector<int> completion_history_; // Number of completions per worker. | 140 std::vector<int> completion_history_; // Number of completions per worker. |
| 139 int thread_started_counter_; // Used to issue unique id to workers. | 141 int thread_started_counter_; // Used to issue unique id to workers. |
| 140 int shutdown_task_count_; // Number of tasks told to shutdown | 142 int shutdown_task_count_; // Number of tasks told to shutdown |
| 141 int task_count_; // Number of assignment tasks waiting to be processed. | 143 int task_count_; // Number of assignment tasks waiting to be processed. |
| 142 TimeDelta worker_delay_; // Time each task takes to complete. | 144 TimeDelta worker_delay_; // Time each task takes to complete. |
| 143 bool allow_help_requests_; // Workers can signal more workers. | 145 bool allow_help_requests_; // Workers can signal more workers. |
| 144 bool shutdown_; // Set when threads need to terminate. | 146 bool shutdown_; // Set when threads need to terminate. |
| 145 | 147 |
| 146 DFAKE_MUTEX(locked_methods_); | 148 DFAKE_MUTEX(locked_methods_); |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 base::AutoLock auto_lock(lock_); | 759 base::AutoLock auto_lock(lock_); |
| 758 // Send notification that we completed our "work." | 760 // Send notification that we completed our "work." |
| 759 WorkIsCompleted(thread_id); | 761 WorkIsCompleted(thread_id); |
| 760 } | 762 } |
| 761 } | 763 } |
| 762 } | 764 } |
| 763 | 765 |
| 764 } // namespace | 766 } // namespace |
| 765 | 767 |
| 766 } // namespace base | 768 } // namespace base |
| OLD | NEW |