| Index: chrome/profiling/stack.h
|
| diff --git a/chrome/profiling/stack.h b/chrome/profiling/stack.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..98ed7691b1697806ee56b8e4d082d4943fde16f2
|
| --- /dev/null
|
| +++ b/chrome/profiling/stack.h
|
| @@ -0,0 +1,65 @@
|
| +// 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_H_
|
| +#define CHROME_PROFILING_STACK_H_
|
| +
|
| +#include <functional>
|
| +#include <vector>
|
| +
|
| +#include "base/macros.h"
|
| +#include "chrome/profiling/address.h"
|
| +
|
| +namespace profiling {
|
| +
|
| +// Holds a move-only stack backtrace and a precomputed hash.
|
| +//
|
| +// This is immutable since we assume it can be read from multiple threads
|
| +// without locking.
|
| +//
|
| +// This class has a ref_count member which is used by the allocation tracker
|
| +// to track references to the stack. The reference counting is managed
|
| +// externally. Tracking live objects with a global atom list in a threadsafe
|
| +// manner is much more difficult if this class derives from RefCount.
|
| +class Stack {
|
| + public:
|
| + explicit Stack(std::vector<Address>&& a);
|
| + ~Stack();
|
| +
|
| + bool operator==(const Stack& other) const;
|
| + bool operator!=(const Stack& other) const;
|
| +
|
| + const std::vector<Address>& addrs() const;
|
| +
|
| + size_t hash() const { return hash_; }
|
| +
|
| + private:
|
| + friend class StackStorage; // Only StackStorage can do ref counting.
|
| +
|
| + // The reference counting is not threadsafe. it's assumed the StackStorage is
|
| + // the only class accessing this, and it's done inside a lock.
|
| + void AddRef() const { ref_count_++; }
|
| + bool Release() const { // Returns whether the result is non-zero.
|
| + return !!(--ref_count_);
|
| + }
|
| +
|
| + std::vector<Address> addrs_;
|
| + size_t hash_;
|
| + mutable int ref_count_ = 0;
|
| +};
|
| +
|
| +} // namespace profiling
|
| +
|
| +namespace std {
|
| +
|
| +template <>
|
| +struct hash<profiling::Stack> {
|
| + using argument_type = profiling::Stack;
|
| + using result_type = size_t;
|
| + result_type operator()(const argument_type& s) const { return s.hash(); }
|
| +};
|
| +
|
| +} // namespace std
|
| +
|
| +#endif // CHROME_PROFILING_STACK_H_
|
|
|