forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler_worker_thread_stack.cc
40 lines (30 loc) · 1.14 KB
/
scheduler_worker_thread_stack.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 (IsEmpty())
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