Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: base/task_scheduler/scheduler_worker_stack.h

Issue 2116163002: Add Lazy Creation and Thread Detachment Support in the Scheduler Worker Pool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fenced Load Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_STACK_H_ 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_WORKER_STACK_H_
6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_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 SchedulerWorker; 18 class SchedulerWorker;
19 19
20 // A stack of SchedulerWorkers. Supports removal of arbitrary 20 // A stack of SchedulerWorkers. Supports removal of arbitrary SchedulerWorkers.
21 // SchedulerWorkers. DCHECKs when a SchedulerWorker is inserted 21 // DCHECKs when a SchedulerWorker is inserted multiple times. SchedulerWorkers
22 // multiple times. SchedulerWorkers are not owned by the stack. Push() is 22 // are not owned by the stack. Push() is amortized O(1). Pop(), Peek(), Size()
23 // amortized O(1). Pop(), Size() and Empty() are O(1). Remove is O(n). This 23 // and Empty() are O(1). Contains() and Remove() are O(n).
24 // class is NOT thread-safe. 24 // This class is NOT thread-safe.
25 class BASE_EXPORT SchedulerWorkerStack { 25 class BASE_EXPORT SchedulerWorkerStack {
26 public: 26 public:
27 SchedulerWorkerStack(); 27 SchedulerWorkerStack();
28 ~SchedulerWorkerStack(); 28 ~SchedulerWorkerStack();
29 29
30 // Inserts |worker| at the top of the stack. |worker| must not already be on 30 // Inserts |worker| at the top of the stack. |worker| must not already be on
31 // the stack. 31 // the stack.
32 void Push(SchedulerWorker* worker); 32 void Push(SchedulerWorker* worker);
33 33
34 // Removes the top SchedulerWorker 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 SchedulerWorker* Pop(); 36 SchedulerWorker* Pop();
37 37
38 // Returns the top SchedulerWorker from the stack, nullptr if empty.
39 SchedulerWorker* Peek() const;
40
41 // Returns true if |worker| is already on the stack.
42 bool Contains(const SchedulerWorker* worker) const;
43
38 // Removes |worker| from the stack. 44 // Removes |worker| from the stack.
39 void Remove(const SchedulerWorker* worker); 45 void Remove(const SchedulerWorker* worker);
40 46
41 // Returns the number of SchedulerWorkers on the stack. 47 // Returns the number of SchedulerWorkers on the stack.
42 size_t Size() const { return stack_.size(); } 48 size_t Size() const { return stack_.size(); }
43 49
44 // Returns true if the stack is empty. 50 // Returns true if the stack is empty.
45 bool IsEmpty() const { return stack_.empty(); } 51 bool IsEmpty() const { return stack_.empty(); }
46 52
47 private: 53 private:
48 std::vector<SchedulerWorker*> stack_; 54 std::vector<SchedulerWorker*> stack_;
49 55
50 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerStack); 56 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerStack);
51 }; 57 };
52 58
53 } // namespace internal 59 } // namespace internal
54 } // namespace base 60 } // namespace base
55 61
56 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_STACK_H_ 62 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_STACK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698