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 #include "base/task_scheduler/scheduler_worker_thread_stack.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "base/logging.h" |
| 10 |
| 11 namespace base { |
| 12 namespace internal { |
| 13 |
| 14 SchedulerWorkerThreadStack::SchedulerWorkerThreadStack() = default; |
| 15 |
| 16 SchedulerWorkerThreadStack::~SchedulerWorkerThreadStack() = default; |
| 17 |
| 18 void SchedulerWorkerThreadStack::Push(SchedulerWorkerThread* worker_thread) { |
| 19 DCHECK(std::find(stack_.begin(), stack_.end(), worker_thread) == stack_.end()) |
| 20 << "SchedulerWorkerThread already on stack"; |
| 21 stack_.push_back(worker_thread); |
| 22 } |
| 23 |
| 24 SchedulerWorkerThread* SchedulerWorkerThreadStack::Pop() { |
| 25 if (IsEmpty()) |
| 26 return nullptr; |
| 27 SchedulerWorkerThread* const worker_thread = stack_.back(); |
| 28 stack_.pop_back(); |
| 29 return worker_thread; |
| 30 } |
| 31 |
| 32 void SchedulerWorkerThreadStack::Remove( |
| 33 const SchedulerWorkerThread* worker_thread) { |
| 34 auto it = std::find(stack_.begin(), stack_.end(), worker_thread); |
| 35 if (it != stack_.end()) |
| 36 stack_.erase(it); |
| 37 } |
| 38 |
| 39 } // namespace internal |
| 40 } // namespace base |
OLD | NEW |