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

Unified Diff: base/task_scheduler/scheduler_worker_thread_stack.h

Issue 1892033003: TaskScheduler [10] SchedulerWorkerThreadStack (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@9_single_thread
Patch Set: CR danakj #44 (Empty -> IsEmpty) Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/task_scheduler/scheduler_thread_pool.cc ('k') | base/task_scheduler/scheduler_worker_thread_stack.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/task_scheduler/scheduler_worker_thread_stack.h
diff --git a/base/task_scheduler/scheduler_worker_thread_stack.h b/base/task_scheduler/scheduler_worker_thread_stack.h
new file mode 100644
index 0000000000000000000000000000000000000000..f669af1dcd2f5addae64ca8cf556343e2210cc10
--- /dev/null
+++ b/base/task_scheduler/scheduler_worker_thread_stack.h
@@ -0,0 +1,56 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_STACK_H_
+#define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_STACK_H_
+
+#include <stddef.h>
+
+#include <vector>
+
+#include "base/base_export.h"
+#include "base/macros.h"
+
+namespace base {
+namespace internal {
+
+class SchedulerWorkerThread;
+
+// A stack of SchedulerWorkerThreads. Supports removal of arbitrary
+// SchedulerWorkerThreads. DCHECKs when a SchedulerWorkerThread is inserted
+// multiple times. SchedulerWorkerThreads are not owned by the stack. Push() is
+// amortized O(1). Pop(), Size() and Empty() are O(1). Remove is O(n). This
+// class is NOT thread-safe.
+class BASE_EXPORT SchedulerWorkerThreadStack {
+ public:
+ SchedulerWorkerThreadStack();
+ ~SchedulerWorkerThreadStack();
+
+ // Inserts |worker_thread| at the top of the stack. |worker_thread| must not
+ // already be on the stack.
+ void Push(SchedulerWorkerThread* worker_thread);
+
+ // Removes the top SchedulerWorkerThread from the stack and returns it.
+ // Returns nullptr if the stack is empty.
+ SchedulerWorkerThread* Pop();
+
+ // Removes |worker_thread| from the stack.
+ void Remove(const SchedulerWorkerThread* worker_thread);
+
+ // Returns the number of SchedulerWorkerThreads on the stack.
+ size_t Size() const { return stack_.size(); }
+
+ // Returns true if the stack is empty.
+ bool IsEmpty() const { return stack_.empty(); }
+
+ private:
+ std::vector<SchedulerWorkerThread*> stack_;
+
+ DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerThreadStack);
+};
+
+} // namespace internal
+} // namespace base
+
+#endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_STACK_H_
« no previous file with comments | « base/task_scheduler/scheduler_thread_pool.cc ('k') | base/task_scheduler/scheduler_worker_thread_stack.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698