| 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 #ifndef CHROME_PROFILING_ADDRESS_H_ |
| 6 #define CHROME_PROFILING_ADDRESS_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <functional> |
| 11 #include <iosfwd> |
| 12 |
| 13 #include "base/hash.h" |
| 14 |
| 15 namespace profiling { |
| 16 |
| 17 // Wrapper around an address in the instrumented process. This wrapper should |
| 18 // be a zero-overhead abstraction around a 64-bit integer (so pass by value) |
| 19 // that prevents getting confused between addresses in the local process and |
| 20 // ones in the instrumented process. |
| 21 struct Address { |
| 22 Address() : value(0) {} |
| 23 explicit Address(uint64_t v) : value(v) {} |
| 24 |
| 25 uint64_t value; |
| 26 |
| 27 bool operator<(Address other) const { return value < other.value; } |
| 28 bool operator<=(Address other) const { return value <= other.value; } |
| 29 bool operator>(Address other) const { return value > other.value; } |
| 30 bool operator>=(Address other) const { return value >= other.value; } |
| 31 |
| 32 bool operator==(Address other) const { return value == other.value; } |
| 33 bool operator!=(Address other) const { return value != other.value; } |
| 34 |
| 35 Address operator+(int64_t delta) const { return Address(value + delta); } |
| 36 Address operator+=(int64_t delta) { |
| 37 value += delta; |
| 38 return *this; |
| 39 } |
| 40 |
| 41 Address operator-(int64_t delta) const { return Address(value - delta); } |
| 42 Address operator-=(int64_t delta) { |
| 43 value -= delta; |
| 44 return *this; |
| 45 } |
| 46 |
| 47 int64_t operator-(Address a) const { return value - a.value; } |
| 48 }; |
| 49 |
| 50 } // namespace profiling |
| 51 |
| 52 namespace std { |
| 53 |
| 54 template <> |
| 55 struct hash<profiling::Address> { |
| 56 typedef profiling::Address argument_type; |
| 57 typedef uint32_t result_type; |
| 58 result_type operator()(argument_type a) const { |
| 59 return base::Hash(reinterpret_cast<char*>(&a.value), sizeof(int64_t)); |
| 60 } |
| 61 }; |
| 62 |
| 63 } // namespace std |
| 64 |
| 65 std::ostream& operator<<(std::ostream& out, profiling::Address a); |
| 66 |
| 67 #endif // CHROME_PROFILING_ADDRESS_H_ |
| OLD | NEW |