1 : // Copyright 2015 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // Declares a template class for handling conversions from trace file
16 : // pointers to live pointers.
17 : #ifndef SYZYGY_BARD_TRACE_LIVE_MAP_H_
18 : #define SYZYGY_BARD_TRACE_LIVE_MAP_H_
19 :
20 : #include <map>
21 :
22 : #include "base/synchronization/lock.h"
23 :
24 : namespace bard {
25 :
26 : // A template class that holds a bidirectional map, for handling conversions
27 : // from trace file pointers to live pointers, since the addresses for the
28 : // live ones are not the same.
29 : // This class is thread safe for simultaneous access accross multiple threads.
30 : // @tparam T The type of object that the class is mapping.
31 : template <typename T>
32 : class TraceLiveMap {
33 : public:
34 : using Map = std::map<T, T>;
35 :
36 : bool AddMapping(T trace, T live);
37 : bool RemoveMapping(T trace, T live);
38 :
39 : bool GetLiveFromTrace(T trace, T* live);
40 : bool GetTraceFromLive(T live, T* trace);
41 :
42 : // Clears this map.
43 : void Clear();
44 :
45 : // @returns true iff this map is empty.
46 E : bool Empty() const { return trace_live_.empty() && live_trace_.empty(); }
47 :
48 : // @name Simple accessors.
49 : // @{
50 : const Map& trace_live() const { return trace_live_; }
51 E : const Map& live_trace() const { return live_trace_; }
52 : // @}
53 :
54 : private:
55 : Map trace_live_;
56 : Map live_trace_;
57 :
58 : base::Lock lock_;
59 : };
60 :
61 : } // namespace bard
62 :
63 : #include "syzygy/bard/trace_live_map_impl.h"
64 :
65 : #endif // SYZYGY_BARD_TRACE_LIVE_MAP_H_
|