blob: 69f32ec8670aa2490dae46ca7da964aac51504ca [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
Daniel Malea0b464d42013-02-06 16:46:40 +000029FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp) :
30m_synthetic_cached(false),
31m_synthetic_sp()
Enrico Granata5548cb52013-01-28 23:47:25 +000032{
33 SetSummary (summary_sp);
34}
35
Daniel Malea0b464d42013-02-06 16:46:40 +000036FormatCache::Entry::Entry (lldb::SyntheticChildrenSP synthetic_sp) :
37m_summary_cached(false),
38m_summary_sp()
Enrico Granata5548cb52013-01-28 23:47:25 +000039{
40 SetSynthetic (synthetic_sp);
41}
42
Daniel Malea0b464d42013-02-06 16:46:40 +000043FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp,lldb::SyntheticChildrenSP synthetic_sp)
Enrico Granata5548cb52013-01-28 23:47:25 +000044{
45 SetSummary (summary_sp);
46 SetSynthetic (synthetic_sp);
47}
48
49bool
50FormatCache::Entry::IsSummaryCached ()
51{
52 return m_summary_cached;
53}
54
55bool
56FormatCache::Entry::IsSyntheticCached ()
57{
58 return m_synthetic_cached;
59}
60
61lldb::TypeSummaryImplSP
62FormatCache::Entry::GetSummary ()
63{
64 return m_summary_sp;
65}
66
67lldb::SyntheticChildrenSP
68FormatCache::Entry::GetSynthetic ()
69{
70 return m_synthetic_sp;
71}
72
73void
74FormatCache::Entry::SetSummary (lldb::TypeSummaryImplSP summary_sp)
75{
76 m_summary_cached = true;
77 m_summary_sp = summary_sp;
78}
79
80void
81FormatCache::Entry::SetSynthetic (lldb::SyntheticChildrenSP synthetic_sp)
82{
83 m_synthetic_cached = true;
84 m_synthetic_sp = synthetic_sp;
85}
86
87FormatCache::FormatCache () :
88m_map(),
89m_mutex (Mutex::eMutexTypeRecursive)
90#ifdef LLDB_CONFIGURATION_DEBUG
91,m_cache_hits(0),m_cache_misses(0)
92#endif
93{
94}
95
96FormatCache::Entry&
97FormatCache::GetEntry (const ConstString& type)
98{
99 auto i = m_map.find(type),
100 e = m_map.end();
101 if (i != e)
102 return i->second;
103 m_map[type] = FormatCache::Entry();
104 return m_map[type];
105}
106
107bool
108FormatCache::GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
109{
110 Mutex::Locker lock(m_mutex);
111 auto entry = GetEntry(type);
112 if (entry.IsSummaryCached())
113 {
114#ifdef LLDB_CONFIGURATION_DEBUG
115 m_cache_hits++;
116#endif
117 summary_sp = entry.GetSummary();
118 return true;
119 }
120#ifdef LLDB_CONFIGURATION_DEBUG
121 m_cache_misses++;
122#endif
123 summary_sp.reset();
124 return false;
125}
126
127bool
128FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
129{
130 Mutex::Locker lock(m_mutex);
131 auto entry = GetEntry(type);
132 if (entry.IsSyntheticCached())
133 {
134#ifdef LLDB_CONFIGURATION_DEBUG
135 m_cache_hits++;
136#endif
137 synthetic_sp = entry.GetSynthetic();
138 return true;
139 }
140#ifdef LLDB_CONFIGURATION_DEBUG
141 m_cache_misses++;
142#endif
143 synthetic_sp.reset();
144 return false;
145}
146
147void
148FormatCache::SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
149{
150 Mutex::Locker lock(m_mutex);
151 GetEntry(type).SetSummary(summary_sp);
152}
153
154void
155FormatCache::SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
156{
157 Mutex::Locker lock(m_mutex);
158 GetEntry(type).SetSynthetic(synthetic_sp);
159}
160
161void
162FormatCache::Clear ()
163{
164 Mutex::Locker lock(m_mutex);
165 m_map.clear();
166}
167