| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 "chrome/profiling/stack_storage.h" |
| 6 |
| 7 #include "chrome/profiling/stack.h" |
| 8 |
| 9 namespace profiling { |
| 10 |
| 11 StackStorage::StackStorage() {} |
| 12 |
| 13 StackStorage::~StackStorage() {} |
| 14 |
| 15 StackStorage::Key StackStorage::Insert(Stack&& stack) { |
| 16 base::AutoLock lock(lock_); |
| 17 |
| 18 StackStorage::Key key = stacks_.insert(std::move(stack)).first; |
| 19 key->AddRef(); |
| 20 return key; |
| 21 } |
| 22 |
| 23 void StackStorage::Free(const Key& key) { |
| 24 base::AutoLock lock(lock_); |
| 25 if (!key->Release()) |
| 26 stacks_.erase(key); |
| 27 } |
| 28 |
| 29 void StackStorage::Free(const std::vector<Key>& keys) { |
| 30 base::AutoLock lock(lock_); |
| 31 for (size_t i = 0; i < keys.size(); i++) { |
| 32 if (!keys[i]->Release()) |
| 33 stacks_.erase(keys[i]); |
| 34 } |
| 35 } |
| 36 |
| 37 const Stack& StackStorage::GetStackForKey(const Key& key) const { |
| 38 // Since the caller should own a reference to the key and the container has |
| 39 // stable iterators, we can access without a lock. |
| 40 return *key; |
| 41 } |
| 42 |
| 43 } // namespace profiling |
| OLD | NEW |