blob: af7b1c386c32493e628f645626bd697dc2d508f7 [file] [log] [blame]
Enrico Granataf509c5e2013-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
Matt Kopecfe21d4f2013-02-21 23:55:31 +000010#include "lldb/lldb-python.h"
11
Enrico Granataf509c5e2013-01-28 23:47:25 +000012// C Includes
13
14// C++ Includes
15
16// Other libraries and framework includes
17
18// Project includes
19#include "lldb/DataFormatters/FormatCache.h"
20
21using namespace lldb;
22using namespace lldb_private;
23
24FormatCache::Entry::Entry () :
25m_summary_cached(false),
26m_synthetic_cached(false),
Daniel Malea77332ba2013-01-30 01:01:11 +000027m_summary_sp(),
28m_synthetic_sp()
Enrico Granataf509c5e2013-01-28 23:47:25 +000029{}
30
Daniel Malea04334192013-02-06 16:46:40 +000031FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp) :
32m_synthetic_cached(false),
33m_synthetic_sp()
Enrico Granataf509c5e2013-01-28 23:47:25 +000034{
35 SetSummary (summary_sp);
36}
37
Daniel Malea04334192013-02-06 16:46:40 +000038FormatCache::Entry::Entry (lldb::SyntheticChildrenSP synthetic_sp) :
39m_summary_cached(false),
40m_summary_sp()
Enrico Granataf509c5e2013-01-28 23:47:25 +000041{
42 SetSynthetic (synthetic_sp);
43}
44
Daniel Malea04334192013-02-06 16:46:40 +000045FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp,lldb::SyntheticChildrenSP synthetic_sp)
Enrico Granataf509c5e2013-01-28 23:47:25 +000046{
47 SetSummary (summary_sp);
48 SetSynthetic (synthetic_sp);
49}
50
51bool
52FormatCache::Entry::IsSummaryCached ()
53{
54 return m_summary_cached;
55}
56
57bool
58FormatCache::Entry::IsSyntheticCached ()
59{
60 return m_synthetic_cached;
61}
62
63lldb::TypeSummaryImplSP
64FormatCache::Entry::GetSummary ()
65{
66 return m_summary_sp;
67}
68
69lldb::SyntheticChildrenSP
70FormatCache::Entry::GetSynthetic ()
71{
72 return m_synthetic_sp;
73}
74
75void
76FormatCache::Entry::SetSummary (lldb::TypeSummaryImplSP summary_sp)
77{
78 m_summary_cached = true;
79 m_summary_sp = summary_sp;
80}
81
82void
83FormatCache::Entry::SetSynthetic (lldb::SyntheticChildrenSP synthetic_sp)
84{
85 m_synthetic_cached = true;
86 m_synthetic_sp = synthetic_sp;
87}
88
89FormatCache::FormatCache () :
90m_map(),
91m_mutex (Mutex::eMutexTypeRecursive)
92#ifdef LLDB_CONFIGURATION_DEBUG
93,m_cache_hits(0),m_cache_misses(0)
94#endif
95{
96}
97
98FormatCache::Entry&
99FormatCache::GetEntry (const ConstString& type)
100{
101 auto i = m_map.find(type),
102 e = m_map.end();
103 if (i != e)
104 return i->second;
105 m_map[type] = FormatCache::Entry();
106 return m_map[type];
107}
108
109bool
110FormatCache::GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
111{
112 Mutex::Locker lock(m_mutex);
113 auto entry = GetEntry(type);
114 if (entry.IsSummaryCached())
115 {
116#ifdef LLDB_CONFIGURATION_DEBUG
117 m_cache_hits++;
118#endif
119 summary_sp = entry.GetSummary();
120 return true;
121 }
122#ifdef LLDB_CONFIGURATION_DEBUG
123 m_cache_misses++;
124#endif
125 summary_sp.reset();
126 return false;
127}
128
129bool
130FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
131{
132 Mutex::Locker lock(m_mutex);
133 auto entry = GetEntry(type);
134 if (entry.IsSyntheticCached())
135 {
136#ifdef LLDB_CONFIGURATION_DEBUG
137 m_cache_hits++;
138#endif
139 synthetic_sp = entry.GetSynthetic();
140 return true;
141 }
142#ifdef LLDB_CONFIGURATION_DEBUG
143 m_cache_misses++;
144#endif
145 synthetic_sp.reset();
146 return false;
147}
148
149void
150FormatCache::SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
151{
152 Mutex::Locker lock(m_mutex);
153 GetEntry(type).SetSummary(summary_sp);
154}
155
156void
157FormatCache::SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
158{
159 Mutex::Locker lock(m_mutex);
160 GetEntry(type).SetSynthetic(synthetic_sp);
161}
162
163void
164FormatCache::Clear ()
165{
166 Mutex::Locker lock(m_mutex);
167 m_map.clear();
168}
169