OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_STACK_H_ | 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_WORKER_STACK_H_ |
6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_STACK_H_ | 6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_STACK_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 namespace internal { | 16 namespace internal { |
17 | 17 |
18 class SchedulerWorkerThread; | 18 class SchedulerWorker; |
19 | 19 |
20 // A stack of SchedulerWorkerThreads. Supports removal of arbitrary | 20 // A stack of SchedulerWorkers. Supports removal of arbitrary |
21 // SchedulerWorkerThreads. DCHECKs when a SchedulerWorkerThread is inserted | 21 // SchedulerWorkers. DCHECKs when a SchedulerWorker is inserted |
22 // multiple times. SchedulerWorkerThreads are not owned by the stack. Push() is | 22 // multiple times. SchedulerWorkers are not owned by the stack. Push() is |
23 // amortized O(1). Pop(), Size() and Empty() are O(1). Remove is O(n). This | 23 // amortized O(1). Pop(), Size() and Empty() are O(1). Remove is O(n). This |
24 // class is NOT thread-safe. | 24 // class is NOT thread-safe. |
25 class BASE_EXPORT SchedulerWorkerThreadStack { | 25 class BASE_EXPORT SchedulerWorkerStack { |
26 public: | 26 public: |
27 SchedulerWorkerThreadStack(); | 27 SchedulerWorkerStack(); |
28 ~SchedulerWorkerThreadStack(); | 28 ~SchedulerWorkerStack(); |
29 | 29 |
30 // Inserts |worker_thread| at the top of the stack. |worker_thread| must not | 30 // Inserts |worker| at the top of the stack. |worker| must not already be on |
31 // already be on the stack. | 31 // the stack. |
32 void Push(SchedulerWorkerThread* worker_thread); | 32 void Push(SchedulerWorker* worker); |
33 | 33 |
34 // Removes the top SchedulerWorkerThread from the stack and returns it. | 34 // Removes the top SchedulerWorker from the stack and returns it. |
35 // Returns nullptr if the stack is empty. | 35 // Returns nullptr if the stack is empty. |
36 SchedulerWorkerThread* Pop(); | 36 SchedulerWorker* Pop(); |
37 | 37 |
38 // Removes |worker_thread| from the stack. | 38 // Removes |worker| from the stack. |
39 void Remove(const SchedulerWorkerThread* worker_thread); | 39 void Remove(const SchedulerWorker* worker); |
40 | 40 |
41 // Returns the number of SchedulerWorkerThreads on the stack. | 41 // Returns the number of SchedulerWorkers on the stack. |
42 size_t Size() const { return stack_.size(); } | 42 size_t Size() const { return stack_.size(); } |
43 | 43 |
44 // Returns true if the stack is empty. | 44 // Returns true if the stack is empty. |
45 bool IsEmpty() const { return stack_.empty(); } | 45 bool IsEmpty() const { return stack_.empty(); } |
46 | 46 |
47 private: | 47 private: |
48 std::vector<SchedulerWorkerThread*> stack_; | 48 std::vector<SchedulerWorker*> stack_; |
49 | 49 |
50 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerThreadStack); | 50 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerStack); |
51 }; | 51 }; |
52 | 52 |
53 } // namespace internal | 53 } // namespace internal |
54 } // namespace base | 54 } // namespace base |
55 | 55 |
56 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_STACK_H_ | 56 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_STACK_H_ |
OLD | NEW |