Chromium Code Reviews| Index: chrome/profiling/stack_storage.cc |
| diff --git a/chrome/profiling/stack_storage.cc b/chrome/profiling/stack_storage.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..40623a9d2b138dfdc41433e073e6aa81e7311bc0 |
| --- /dev/null |
| +++ b/chrome/profiling/stack_storage.cc |
| @@ -0,0 +1,43 @@ |
| +// Copyright 2017 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 "chrome/profiling/stack_storage.h" |
| + |
| +#include "chrome/profiling/stack.h" |
| + |
| +namespace profiling { |
| + |
| +StackStorage::StackStorage() {} |
| + |
| +StackStorage::~StackStorage() {} |
| + |
| +StackStorage::Key StackStorage::Insert(Stack&& stack) { |
| + base::AutoLock lock(lock_); |
| + |
| + StackStorage::Key key = stacks_.insert(std::move(stack)).first; |
| + key->AddRef(); |
| + return key; |
| +} |
| + |
| +void StackStorage::Free(const Key& key) { |
| + base::AutoLock lock(lock_); |
| + if (!key->Release()) |
| + stacks_.erase(key); |
|
Boris Vidolov
2017/06/17 03:13:15
I am wondering if we really need to release stacks
brettw
2017/06/19 23:29:46
I think freeing the stacks makes a big difference
|
| +} |
| + |
| +void StackStorage::Free(const std::vector<Key>& keys) { |
| + base::AutoLock lock(lock_); |
| + for (size_t i = 0; i < keys.size(); i++) { |
| + if (!keys[i]->Release()) |
| + stacks_.erase(keys[i]); |
| + } |
| +} |
| + |
| +const Stack& StackStorage::GetStackForKey(const Key& key) const { |
| + // Since the caller should own a reference to the key and the container has |
| + // stable iterators, we can access without a lock. |
| + return *key; |
| +} |
| + |
| +} // namespace profiling |