blob: 67a2e9e802faefd772584b3678f8504d14c89ffc [file] [log] [blame]
Enrico Granata5548cb52013-01-28 23:47:25 +00001//===-- FormatCache.cpp ------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// C Includes
11
12// C++ Includes
13
14// Other libraries and framework includes
15
16// Project includes
17#include "lldb/DataFormatters/FormatCache.h"
18
19using namespace lldb;
20using namespace lldb_private;
21
22FormatCache::Entry::Entry () :
23m_summary_cached(false),
24m_synthetic_cached(false),
Daniel Malea30b95a32013-01-30 01:01:11 +000025m_summary_sp(),
26m_synthetic_sp()
Enrico Granata5548cb52013-01-28 23:47:25 +000027{}
28
29FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp) : FormatCache::Entry()
30{
31 SetSummary (summary_sp);
32}
33
34FormatCache::Entry::Entry (lldb::SyntheticChildrenSP synthetic_sp) : FormatCache::Entry()
35{
36 SetSynthetic (synthetic_sp);
37}
38
39FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp,lldb::SyntheticChildrenSP synthetic_sp) : FormatCache::Entry()
40{
41 SetSummary (summary_sp);
42 SetSynthetic (synthetic_sp);
43}
44
45bool
46FormatCache::Entry::IsSummaryCached ()
47{
48 return m_summary_cached;
49}
50
51bool
52FormatCache::Entry::IsSyntheticCached ()
53{
54 return m_synthetic_cached;
55}
56
57lldb::TypeSummaryImplSP
58FormatCache::Entry::GetSummary ()
59{
60 return m_summary_sp;
61}
62
63lldb::SyntheticChildrenSP
64FormatCache::Entry::GetSynthetic ()
65{
66 return m_synthetic_sp;
67}
68
69void
70FormatCache::Entry::SetSummary (lldb::TypeSummaryImplSP summary_sp)
71{
72 m_summary_cached = true;
73 m_summary_sp = summary_sp;
74}
75
76void
77FormatCache::Entry::SetSynthetic (lldb::SyntheticChildrenSP synthetic_sp)
78{
79 m_synthetic_cached = true;
80 m_synthetic_sp = synthetic_sp;
81}
82
83FormatCache::FormatCache () :
84m_map(),
85m_mutex (Mutex::eMutexTypeRecursive)
86#ifdef LLDB_CONFIGURATION_DEBUG
87,m_cache_hits(0),m_cache_misses(0)
88#endif
89{
90}
91
92FormatCache::Entry&
93FormatCache::GetEntry (const ConstString& type)
94{
95 auto i = m_map.find(type),
96 e = m_map.end();
97 if (i != e)
98 return i->second;
99 m_map[type] = FormatCache::Entry();
100 return m_map[type];
101}
102
103bool
104FormatCache::GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
105{
106 Mutex::Locker lock(m_mutex);
107 auto entry = GetEntry(type);
108 if (entry.IsSummaryCached())
109 {
110#ifdef LLDB_CONFIGURATION_DEBUG
111 m_cache_hits++;
112#endif
113 summary_sp = entry.GetSummary();
114 return true;
115 }
116#ifdef LLDB_CONFIGURATION_DEBUG
117 m_cache_misses++;
118#endif
119 summary_sp.reset();
120 return false;
121}
122
123bool
124FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
125{
126 Mutex::Locker lock(m_mutex);
127 auto entry = GetEntry(type);
128 if (entry.IsSyntheticCached())
129 {
130#ifdef LLDB_CONFIGURATION_DEBUG
131 m_cache_hits++;
132#endif
133 synthetic_sp = entry.GetSynthetic();
134 return true;
135 }
136#ifdef LLDB_CONFIGURATION_DEBUG
137 m_cache_misses++;
138#endif
139 synthetic_sp.reset();
140 return false;
141}
142
143void
144FormatCache::SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
145{
146 Mutex::Locker lock(m_mutex);
147 GetEntry(type).SetSummary(summary_sp);
148}
149
150void
151FormatCache::SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
152{
153 Mutex::Locker lock(m_mutex);
154 GetEntry(type).SetSynthetic(synthetic_sp);
155}
156
157void
158FormatCache::Clear ()
159{
160 Mutex::Locker lock(m_mutex);
161 m_map.clear();
162}
163