Commit c34431a5 authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

Use std::deque to store the stack of currently executing tasks

The stack of currently executing stacks includes a PendingTask field. A
pointer to this field is stored in TLS. However, std::vector does not
guarantee pointer stability on resize.

Bug: 1064891
Change-Id: I04eb06c9521722f08fd72826f552cedaffe61b53
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2146349
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarSami Kyöstilä <skyostil@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759017}
parent 6e8c5253
......@@ -44,13 +44,6 @@ GetTLSSequenceManagerImpl() {
} // namespace
// This controls how big the the initial for
// |MainThreadOnly::task_execution_stack| should be. We don't expect to see
// depths of more than 2 unless cooperative scheduling is used on Blink, where
// we might get up to 6. Anyway 10 was chosen because it's a round number
// greater than current anticipated usage.
static constexpr const size_t kInitialTaskExecutionStackReserveCount = 10;
std::unique_ptr<SequenceManager> CreateSequenceManagerOnCurrentThread(
SequenceManager::Settings settings) {
return internal::SequenceManagerImpl::CreateOnCurrentThread(
......@@ -252,7 +245,6 @@ SequenceManagerImpl::MainThreadOnly::MainThreadOnly(
random_generator = std::mt19937_64(RandUint64());
uniform_distribution = std::uniform_real_distribution<double>(0.0, 1.0);
}
task_execution_stack.reserve(kInitialTaskExecutionStackReserveCount);
}
SequenceManagerImpl::MainThreadOnly::~MainThreadOnly() = default;
......
......@@ -5,6 +5,7 @@
#ifndef BASE_TASK_SEQUENCE_MANAGER_SEQUENCE_MANAGER_IMPL_H_
#define BASE_TASK_SEQUENCE_MANAGER_SEQUENCE_MANAGER_IMPL_H_
#include <deque>
#include <list>
#include <map>
#include <memory>
......@@ -12,7 +13,6 @@
#include <set>
#include <unordered_map>
#include <utility>
#include <vector>
#include "base/atomic_sequence_num.h"
#include "base/cancelable_callback.h"
......@@ -302,7 +302,9 @@ class BASE_EXPORT SequenceManagerImpl
bool nesting_observer_registered_ = false;
// Due to nested runloops more than one task can be executing concurrently.
std::vector<ExecutingTask> task_execution_stack;
// Note that this uses std::deque for pointer stability, since pointers to
// objects in this container are stored in TLS.
std::deque<ExecutingTask> task_execution_stack;
Observer* observer = nullptr; // NOT OWNED
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment