Chromium Code Reviews| 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 namespace profiling { | |
| 14 | |
| 15 // Wrapper around an address in the instrumented process. This wrapper should | |
| 16 // be a zero-overhead abstraction around a 64-bit integer (so pass by value) | |
| 17 // that prevents getting confused between addresses in the local process and | |
| 18 // ones in the instrumented process. | |
| 19 struct Address { | |
| 20 Address() : value(0) {} | |
| 21 explicit Address(uint64_t v) : value(v) {} | |
| 22 | |
| 23 uint64_t value; | |
| 24 | |
| 25 bool operator<(Address other) const { return value < other.value; } | |
| 26 bool operator<=(Address other) const { return value <= other.value; } | |
| 27 bool operator>(Address other) const { return value > other.value; } | |
| 28 bool operator>=(Address other) const { return value >= other.value; } | |
| 29 | |
| 30 bool operator==(Address other) const { return value == other.value; } | |
| 31 bool operator!=(Address other) const { return value != other.value; } | |
| 32 | |
| 33 Address operator+(int64_t delta) const { return Address(value + delta); } | |
| 34 Address operator+=(int64_t delta) { | |
| 35 value += delta; | |
| 36 return *this; | |
| 37 } | |
| 38 | |
| 39 Address operator-(int64_t delta) const { return Address(value - delta); } | |
| 40 Address operator-=(int64_t delta) { | |
| 41 value -= delta; | |
| 42 return *this; | |
| 43 } | |
| 44 | |
| 45 int64_t operator-(Address a) const { return value - a.value; } | |
| 46 }; | |
| 47 | |
| 48 } // namespace profiling | |
| 49 | |
| 50 namespace std { | |
| 51 | |
| 52 template <> | |
| 53 struct hash<profiling::Address> { | |
| 54 typedef profiling::Address argument_type; | |
| 55 typedef std::size_t result_type; | |
| 56 result_type operator()(argument_type a) const { | |
| 57 return static_cast<size_t>(a.value); | |
|
awong
2017/06/19 20:00:13
?? Shouldn't this return base::hash(a.value)?
brettw
2017/06/19 23:29:45
Thanks, wrote this long ago as a placeholder and f
| |
| 58 } | |
| 59 }; | |
| 60 | |
| 61 } // namespace std | |
| 62 | |
| 63 std::ostream& operator<<(std::ostream& out, profiling::Address a); | |
| 64 | |
| 65 #endif // CHROME_PROFILING_ADDRESS_H_ | |
| OLD | NEW |