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 m : 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 m : template <typename T>
32 m : class TraceLiveMap {
33 m : public:
34 m : bool AddMapping(T trace, T live);
35 m : bool RemoveMapping(T trace, T live);
36 :
37 m : bool GetLiveFromTrace(T trace, T* live);
38 m : bool GetTraceFromLive(T live, T* trace);
39 :
40 m : private:
41 m : std::map<T, T> trace_live_;
42 m : std::map<T, T> live_trace_;
43 :
44 m : base::Lock lock_;
45 m : };
46 :
47 m : } // namespace bard
48 :
49 : #include "syzygy/bard/trace_live_map_impl.h"
50 :
51 : #endif // SYZYGY_BARD_TRACE_LIVE_MAP_H_
|