| Index: chrome/profiling/stack_storage.h
|
| diff --git a/chrome/profiling/stack_storage.h b/chrome/profiling/stack_storage.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6f00a652f6eafdf00ab632e2d490243dbdaf4821
|
| --- /dev/null
|
| +++ b/chrome/profiling/stack_storage.h
|
| @@ -0,0 +1,51 @@
|
| +// 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.
|
| +
|
| +#ifndef CHROME_PROFILING_STACK_STORAGE_H_
|
| +#define CHROME_PROFILING_STACK_STORAGE_H_
|
| +
|
| +#include <unordered_set>
|
| +#include <vector>
|
| +
|
| +#include "base/macros.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/synchronization/lock.h"
|
| +#include "chrome/profiling/stack.h"
|
| +
|
| +namespace profiling {
|
| +
|
| +// This class is threadsafe.
|
| +class StackStorage {
|
| + public:
|
| + using Container = std::unordered_set<Stack>;
|
| + using Key = Container::iterator;
|
| +
|
| + StackStorage();
|
| + ~StackStorage();
|
| +
|
| + // Adds the give stack to the storage and returns a key to it. If a matching
|
| + // stack already exists, a key to the existing one will be returned.
|
| + //
|
| + // The returned key will have a reference count associated with it, call
|
| + // Free when the key is no longer needed.
|
| + Key Insert(Stack&& stack);
|
| +
|
| + // Frees one reference to a stack.
|
| + void Free(const Key& key);
|
| + void Free(const std::vector<Key>& keys);
|
| +
|
| + // Returns the stack associated with the given key. Assumes the caller holds
|
| + // a key to it that will keep the stack in scope.
|
| + const Stack& GetStackForKey(const Key& key) const;
|
| +
|
| + private:
|
| + mutable base::Lock lock_;
|
| +
|
| + // List of live stacks for de-duping. Protected by the lock_.
|
| + Container stacks_;
|
| +};
|
| +
|
| +} // namespace profiling
|
| +
|
| +#endif // CHROME_PROFILING_STACK_STORAGE_H_
|
|
|