32 template <
typename CacheManager>
35 template <
typename CacheManager>
38 typename std::map<uint32,uint32>::iterator it = m_cache_map.find( item );
39 if (it == m_cache_map.end())
42 if (m_cache_pool.size())
44 list_idx = m_cache_pool.top();
49 list_idx =
uint32( m_cache_list.size() );
50 m_cache_list.push_back( List() );
53 m_cache_map.insert( std::make_pair( item, list_idx ) );
55 List& list = m_cache_list[ list_idx ];
57 list.m_next = m_first;
58 list.m_prev = 0xFFFFFFFFu;
62 if (m_first != 0xFFFFFFFFu)
64 List& first = m_cache_list[ m_first ];
65 first.m_prev = list_idx;
69 if (m_last == 0xFFFFFFFFu)
72 if (m_manager->acquire( item ) ==
false)
73 release_cycle( item );
78 List& list = m_cache_list[ it->second ];
82 touch( it->second, list );
86 template <
typename CacheManager>
89 typename std::map<uint32,uint32>::iterator it = m_cache_map.find( item );
90 const uint32 list_idx = it->second;
92 List& list = m_cache_list[ list_idx ];
93 list.m_pinned =
false;
96 touch( list_idx, list );
99 template <
typename CacheManager>
103 if (m_first == list_idx)
107 if (list.m_prev != 0xFFFFFFFFu)
109 List& prev = m_cache_list[ list.m_prev ];
110 prev.m_next = list.m_next;
112 if (list.m_next != 0xFFFFFFFFu)
114 List&
next = m_cache_list[ list.m_next ];
115 next.m_next = list.m_prev;
118 m_last = list.m_prev;
124 template <
typename CacheManager>
125 void LRU<CacheManager>::release_cycle(
const uint32 item_to_acquire)
129 bool acquired =
false;
133 if (list_idx == 0xFFFFFFFFu)
138 throw cache_overflow();
141 List& list = m_cache_list[ list_idx ];
144 list_idx = list.m_prev;
148 const uint32 prev = list.m_prev;
151 if (list.m_prev != 0xFFFFFFFFu)
153 List& prev = m_cache_list[ list.m_prev ];
154 prev.m_next = list.m_next;
157 m_first = 0xFFFFFFFFu;
159 if (list.m_next != 0xFFFFFFFFu)
161 List&
next = m_cache_list[ list.m_next ];
162 next.m_next = list.m_prev;
165 m_last = list.m_prev;
167 const uint32 item = list.m_item;
170 m_cache_pool.push( list_idx );
173 m_cache_map.erase( m_cache_map.find( item ) );
175 m_manager->release( item );
176 if (acquired ==
false && m_manager->acquire( item_to_acquire ))
182 while (m_manager->low_watermark() ==
false);