Enrico Granata | f509c5e | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 1 | //===-- 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 Kopec | fe21d4f | 2013-02-21 23:55:31 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Enrico Granata | f509c5e | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 12 | // C Includes |
| 13 | |
| 14 | // C++ Includes |
| 15 | |
| 16 | // Other libraries and framework includes |
| 17 | |
| 18 | // Project includes |
| 19 | #include "lldb/DataFormatters/FormatCache.h" |
| 20 | |
| 21 | using namespace lldb; |
| 22 | using namespace lldb_private; |
| 23 | |
| 24 | FormatCache::Entry::Entry () : |
| 25 | m_summary_cached(false), |
| 26 | m_synthetic_cached(false), |
Daniel Malea | 77332ba | 2013-01-30 01:01:11 +0000 | [diff] [blame] | 27 | m_summary_sp(), |
| 28 | m_synthetic_sp() |
Enrico Granata | f509c5e | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 29 | {} |
| 30 | |
Daniel Malea | 0433419 | 2013-02-06 16:46:40 +0000 | [diff] [blame] | 31 | FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp) : |
| 32 | m_synthetic_cached(false), |
| 33 | m_synthetic_sp() |
Enrico Granata | f509c5e | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 34 | { |
| 35 | SetSummary (summary_sp); |
| 36 | } |
| 37 | |
Daniel Malea | 0433419 | 2013-02-06 16:46:40 +0000 | [diff] [blame] | 38 | FormatCache::Entry::Entry (lldb::SyntheticChildrenSP synthetic_sp) : |
| 39 | m_summary_cached(false), |
| 40 | m_summary_sp() |
Enrico Granata | f509c5e | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 41 | { |
| 42 | SetSynthetic (synthetic_sp); |
| 43 | } |
| 44 | |
Daniel Malea | 0433419 | 2013-02-06 16:46:40 +0000 | [diff] [blame] | 45 | FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp,lldb::SyntheticChildrenSP synthetic_sp) |
Enrico Granata | f509c5e | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 46 | { |
| 47 | SetSummary (summary_sp); |
| 48 | SetSynthetic (synthetic_sp); |
| 49 | } |
| 50 | |
| 51 | bool |
| 52 | FormatCache::Entry::IsSummaryCached () |
| 53 | { |
| 54 | return m_summary_cached; |
| 55 | } |
| 56 | |
| 57 | bool |
| 58 | FormatCache::Entry::IsSyntheticCached () |
| 59 | { |
| 60 | return m_synthetic_cached; |
| 61 | } |
| 62 | |
| 63 | lldb::TypeSummaryImplSP |
| 64 | FormatCache::Entry::GetSummary () |
| 65 | { |
| 66 | return m_summary_sp; |
| 67 | } |
| 68 | |
| 69 | lldb::SyntheticChildrenSP |
| 70 | FormatCache::Entry::GetSynthetic () |
| 71 | { |
| 72 | return m_synthetic_sp; |
| 73 | } |
| 74 | |
| 75 | void |
| 76 | FormatCache::Entry::SetSummary (lldb::TypeSummaryImplSP summary_sp) |
| 77 | { |
| 78 | m_summary_cached = true; |
| 79 | m_summary_sp = summary_sp; |
| 80 | } |
| 81 | |
| 82 | void |
| 83 | FormatCache::Entry::SetSynthetic (lldb::SyntheticChildrenSP synthetic_sp) |
| 84 | { |
| 85 | m_synthetic_cached = true; |
| 86 | m_synthetic_sp = synthetic_sp; |
| 87 | } |
| 88 | |
| 89 | FormatCache::FormatCache () : |
| 90 | m_map(), |
| 91 | m_mutex (Mutex::eMutexTypeRecursive) |
| 92 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 93 | ,m_cache_hits(0),m_cache_misses(0) |
| 94 | #endif |
| 95 | { |
| 96 | } |
| 97 | |
| 98 | FormatCache::Entry& |
| 99 | FormatCache::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 | |
| 109 | bool |
| 110 | FormatCache::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 | |
| 129 | bool |
| 130 | FormatCache::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 | |
| 149 | void |
| 150 | FormatCache::SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp) |
| 151 | { |
| 152 | Mutex::Locker lock(m_mutex); |
| 153 | GetEntry(type).SetSummary(summary_sp); |
| 154 | } |
| 155 | |
| 156 | void |
| 157 | FormatCache::SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp) |
| 158 | { |
| 159 | Mutex::Locker lock(m_mutex); |
| 160 | GetEntry(type).SetSynthetic(synthetic_sp); |
| 161 | } |
| 162 | |
| 163 | void |
| 164 | FormatCache::Clear () |
| 165 | { |
| 166 | Mutex::Locker lock(m_mutex); |
| 167 | m_map.clear(); |
| 168 | } |
| 169 | |