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