| 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 <time.h> | 7 #include <time.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 //---------------------------------------------------------------------------- | 95 //---------------------------------------------------------------------------- |
| 96 // The rest of the methods are for use by the controlling master thread (the | 96 // The rest of the methods are for use by the controlling master thread (the |
| 97 // test case code). | 97 // test case code). |
| 98 void ResetHistory(); | 98 void ResetHistory(); |
| 99 int GetMinCompletionsByWorkerThread() const; | 99 int GetMinCompletionsByWorkerThread() const; |
| 100 int GetMaxCompletionsByWorkerThread() const; | 100 int GetMaxCompletionsByWorkerThread() const; |
| 101 int GetNumThreadsTakingAssignments() const; | 101 int GetNumThreadsTakingAssignments() const; |
| 102 int GetNumThreadsCompletingTasks() const; | 102 int GetNumThreadsCompletingTasks() const; |
| 103 int GetNumberOfCompletedTasks() const; | 103 int GetNumberOfCompletedTasks() const; |
| 104 TimeDelta GetWorkTime() const; | |
| 105 | 104 |
| 106 void SetWorkTime(TimeDelta delay); | 105 void SetWorkTime(TimeDelta delay); |
| 107 void SetTaskCount(int count); | 106 void SetTaskCount(int count); |
| 108 void SetAllowHelp(bool allow); | 107 void SetAllowHelp(bool allow); |
| 109 | 108 |
| 110 // The following must be called without locking, and will spin wait until the | 109 // The following must be called without locking, and will spin wait until the |
| 111 // threads are all in a wait state. | 110 // threads are all in a wait state. |
| 112 void SpinUntilAllThreadsAreWaiting(); | 111 void SpinUntilAllThreadsAreWaiting(); |
| 113 void SpinUntilTaskCountLessThan(int task_count); | 112 void SpinUntilTaskCountLessThan(int task_count); |
| 114 | 113 |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 return count; | 643 return count; |
| 645 } | 644 } |
| 646 | 645 |
| 647 int WorkQueue::GetNumberOfCompletedTasks() const { | 646 int WorkQueue::GetNumberOfCompletedTasks() const { |
| 648 int total = 0; | 647 int total = 0; |
| 649 for (int i = 0; i < thread_count_; ++i) | 648 for (int i = 0; i < thread_count_; ++i) |
| 650 total += completion_history_[i]; | 649 total += completion_history_[i]; |
| 651 return total; | 650 return total; |
| 652 } | 651 } |
| 653 | 652 |
| 654 TimeDelta WorkQueue::GetWorkTime() const { | |
| 655 return worker_delay_; | |
| 656 } | |
| 657 | |
| 658 void WorkQueue::SetWorkTime(TimeDelta delay) { | 653 void WorkQueue::SetWorkTime(TimeDelta delay) { |
| 659 worker_delay_ = delay; | 654 worker_delay_ = delay; |
| 660 } | 655 } |
| 661 | 656 |
| 662 void WorkQueue::SetTaskCount(int count) { | 657 void WorkQueue::SetTaskCount(int count) { |
| 663 task_count_ = count; | 658 task_count_ = count; |
| 664 } | 659 } |
| 665 | 660 |
| 666 void WorkQueue::SetAllowHelp(bool allow) { | 661 void WorkQueue::SetAllowHelp(bool allow) { |
| 667 allow_help_requests_ = allow; | 662 allow_help_requests_ = allow; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 base::AutoLock auto_lock(lock_); | 754 base::AutoLock auto_lock(lock_); |
| 760 // Send notification that we completed our "work." | 755 // Send notification that we completed our "work." |
| 761 WorkIsCompleted(thread_id); | 756 WorkIsCompleted(thread_id); |
| 762 } | 757 } |
| 763 } | 758 } |
| 764 } | 759 } |
| 765 | 760 |
| 766 } // namespace | 761 } // namespace |
| 767 | 762 |
| 768 } // namespace base | 763 } // namespace base |
| OLD | NEW |