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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // cases will validate that the WorkQueue has records showing that the desired | 55 // cases will validate that the WorkQueue has records showing that the desired |
56 // activities were performed. | 56 // activities were performed. |
57 //------------------------------------------------------------------------------ | 57 //------------------------------------------------------------------------------ |
58 | 58 |
59 // Callers are responsible for synchronizing access to the following class. | 59 // Callers are responsible for synchronizing access to the following class. |
60 // The WorkQueue::lock_, as accessed via WorkQueue::lock(), should be used for | 60 // The WorkQueue::lock_, as accessed via WorkQueue::lock(), should be used for |
61 // all synchronized access. | 61 // all synchronized access. |
62 class WorkQueue : public PlatformThread::Delegate { | 62 class WorkQueue : public PlatformThread::Delegate { |
63 public: | 63 public: |
64 explicit WorkQueue(int thread_count); | 64 explicit WorkQueue(int thread_count); |
65 ~WorkQueue(); | 65 virtual ~WorkQueue(); |
66 | 66 |
67 // PlatformThread::Delegate interface. | 67 // PlatformThread::Delegate interface. |
68 void ThreadMain(); | 68 virtual void ThreadMain() OVERRIDE; |
69 | 69 |
70 //---------------------------------------------------------------------------- | 70 //---------------------------------------------------------------------------- |
71 // Worker threads only call the following methods. | 71 // Worker threads only call the following methods. |
72 // They should use the lock to get exclusive access. | 72 // They should use the lock to get exclusive access. |
73 int GetThreadId(); // Get an ID assigned to a thread.. | 73 int GetThreadId(); // Get an ID assigned to a thread.. |
74 bool EveryIdWasAllocated() const; // Indicates that all IDs were handed out. | 74 bool EveryIdWasAllocated() const; // Indicates that all IDs were handed out. |
75 TimeDelta GetAnAssignment(int thread_id); // Get a work task duration. | 75 TimeDelta GetAnAssignment(int thread_id); // Get a work task duration. |
76 void WorkIsCompleted(int thread_id); | 76 void WorkIsCompleted(int thread_id); |
77 | 77 |
78 int task_count() const; | 78 int task_count() const; |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 base::AutoLock auto_lock(lock_); | 706 base::AutoLock auto_lock(lock_); |
707 // Send notification that we completed our "work." | 707 // Send notification that we completed our "work." |
708 WorkIsCompleted(thread_id); | 708 WorkIsCompleted(thread_id); |
709 } | 709 } |
710 } | 710 } |
711 } | 711 } |
712 | 712 |
713 } // namespace | 713 } // namespace |
714 | 714 |
715 } // namespace base | 715 } // namespace base |
OLD | NEW |