|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Daniel Cheng <dcheng@chromium.org> |
| 3 | +Date: Fri, 10 Apr 2020 00:43:45 +0000 |
| 4 | +Subject: Use std::deque to store the stack of currently executing tasks |
| 5 | +MIME-Version: 1.0 |
| 6 | +Content-Type: text/plain; charset=UTF-8 |
| 7 | +Content-Transfer-Encoding: 8bit |
| 8 | + |
| 9 | +The stack of currently executing stacks includes a PendingTask field. A |
| 10 | +pointer to this field is stored in TLS. However, std::vector does not |
| 11 | +guarantee pointer stability on resize. |
| 12 | + |
| 13 | +(cherry picked from commit c34431a597aba8f4374975217d97a73eaf7d1f18) |
| 14 | + |
| 15 | +Bug: 1064891 |
| 16 | +Change-Id: I04eb06c9521722f08fd72826f552cedaffe61b53 |
| 17 | +Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2146349 |
| 18 | +Commit-Queue: Daniel Cheng <dcheng@chromium.org> |
| 19 | +Reviewed-by: Sami Kyöstilä <skyostil@chromium.org> |
| 20 | +Reviewed-by: François Doray <fdoray@chromium.org> |
| 21 | +Cr-Original-Commit-Position: refs/heads/master@{#759017} |
| 22 | +Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2158048 |
| 23 | +Cr-Commit-Position: refs/branch-heads/4044@{#970} |
| 24 | +Cr-Branched-From: a6d9daf149a473ceea37f629c41d4527bf2055bd-refs/heads/master@{#737173} |
| 25 | + |
| 26 | +diff --git a/base/task/sequence_manager/sequence_manager_impl.cc b/base/task/sequence_manager/sequence_manager_impl.cc |
| 27 | +index 26977d6687b9071c137c95c30c2587fb98cf2110..90c8f3456d3d25364ca69a54628a4a54b76a2d56 100644 |
| 28 | +--- a/base/task/sequence_manager/sequence_manager_impl.cc |
| 29 | ++++ b/base/task/sequence_manager/sequence_manager_impl.cc |
| 30 | +@@ -44,13 +44,6 @@ GetTLSSequenceManagerImpl() { |
| 31 | + |
| 32 | + } // namespace |
| 33 | + |
| 34 | +-// This controls how big the the initial for |
| 35 | +-// |MainThreadOnly::task_execution_stack| should be. We don't expect to see |
| 36 | +-// depths of more than 2 unless cooperative scheduling is used on Blink, where |
| 37 | +-// we might get up to 6. Anyway 10 was chosen because it's a round number |
| 38 | +-// greater than current anticipated usage. |
| 39 | +-static constexpr const size_t kInitialTaskExecutionStackReserveCount = 10; |
| 40 | +- |
| 41 | + std::unique_ptr<SequenceManager> CreateSequenceManagerOnCurrentThread( |
| 42 | + SequenceManager::Settings settings) { |
| 43 | + return internal::SequenceManagerImpl::CreateOnCurrentThread( |
| 44 | +@@ -254,7 +247,6 @@ SequenceManagerImpl::MainThreadOnly::MainThreadOnly( |
| 45 | + random_generator = std::mt19937_64(RandUint64()); |
| 46 | + uniform_distribution = std::uniform_real_distribution<double>(0.0, 1.0); |
| 47 | + } |
| 48 | +- task_execution_stack.reserve(kInitialTaskExecutionStackReserveCount); |
| 49 | + } |
| 50 | + |
| 51 | + SequenceManagerImpl::MainThreadOnly::~MainThreadOnly() = default; |
| 52 | +diff --git a/base/task/sequence_manager/sequence_manager_impl.h b/base/task/sequence_manager/sequence_manager_impl.h |
| 53 | +index a8c1659f52ab18630c903b94d7bb677f600c890c..f464bfb01cb85e1f440c9af6956cdcbbe9ee1625 100644 |
| 54 | +--- a/base/task/sequence_manager/sequence_manager_impl.h |
| 55 | ++++ b/base/task/sequence_manager/sequence_manager_impl.h |
| 56 | +@@ -5,6 +5,7 @@ |
| 57 | + #ifndef BASE_TASK_SEQUENCE_MANAGER_SEQUENCE_MANAGER_IMPL_H_ |
| 58 | + #define BASE_TASK_SEQUENCE_MANAGER_SEQUENCE_MANAGER_IMPL_H_ |
| 59 | + |
| 60 | ++#include <deque> |
| 61 | + #include <list> |
| 62 | + #include <map> |
| 63 | + #include <memory> |
| 64 | +@@ -12,7 +13,6 @@ |
| 65 | + #include <set> |
| 66 | + #include <unordered_map> |
| 67 | + #include <utility> |
| 68 | +-#include <vector> |
| 69 | + |
| 70 | + #include "base/atomic_sequence_num.h" |
| 71 | + #include "base/cancelable_callback.h" |
| 72 | +@@ -306,7 +306,9 @@ class BASE_EXPORT SequenceManagerImpl |
| 73 | + bool nesting_observer_registered_ = false; |
| 74 | + |
| 75 | + // Due to nested runloops more than one task can be executing concurrently. |
| 76 | +- std::vector<ExecutingTask> task_execution_stack; |
| 77 | ++ // Note that this uses std::deque for pointer stability, since pointers to |
| 78 | ++ // objects in this container are stored in TLS. |
| 79 | ++ std::deque<ExecutingTask> task_execution_stack; |
| 80 | + |
| 81 | + Observer* observer = nullptr; // NOT OWNED |
| 82 | + |
0 commit comments