Chromium Code Reviews| Index: base/task_scheduler/scheduler_worker_thread_stack.cc |
| diff --git a/base/task_scheduler/scheduler_worker_thread_stack.cc b/base/task_scheduler/scheduler_worker_thread_stack.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d9c521e46ea1e3a3b0aa51b2e6fc183867402598 |
| --- /dev/null |
| +++ b/base/task_scheduler/scheduler_worker_thread_stack.cc |
| @@ -0,0 +1,40 @@ |
| +// 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. |
| + |
| +#include "base/task_scheduler/scheduler_worker_thread_stack.h" |
| + |
| +#include <algorithm> |
| + |
| +#include "base/logging.h" |
| + |
| +namespace base { |
| +namespace internal { |
| + |
| +SchedulerWorkerThreadStack::SchedulerWorkerThreadStack() = default; |
| + |
| +SchedulerWorkerThreadStack::~SchedulerWorkerThreadStack() = default; |
| + |
| +void SchedulerWorkerThreadStack::Push(SchedulerWorkerThread* worker_thread) { |
| + DCHECK(std::find(stack_.begin(), stack_.end(), worker_thread) == stack_.end()) |
| + << "SchedulerWorkerThread already on stack"; |
| + stack_.push_back(worker_thread); |
| +} |
| + |
| +SchedulerWorkerThread* SchedulerWorkerThreadStack::Pop() { |
| + if (Empty()) |
|
danakj
2016/04/22 21:08:12
nit: usually contains DCHECK this and expect the c
fdoray
2016/04/22 22:23:38
I prefer keeping this as-is because it requires le
|
| + return nullptr; |
| + SchedulerWorkerThread* const worker_thread = stack_.back(); |
| + stack_.pop_back(); |
| + return worker_thread; |
| +} |
| + |
| +void SchedulerWorkerThreadStack::Remove( |
| + const SchedulerWorkerThread* worker_thread) { |
| + auto it = std::find(stack_.begin(), stack_.end(), worker_thread); |
| + if (it != stack_.end()) |
| + stack_.erase(it); |
| +} |
| + |
| +} // namespace internal |
| +} // namespace base |