13
0

create sortable, linear list for cache clearing on demand, rather than trying to maintain it in parallel with the cache map

This commit is contained in:
Paul Davis 2015-06-23 08:42:55 -04:00
parent b808ca897b
commit dece3c20ca
2 changed files with 10 additions and 4 deletions

View File

@ -164,7 +164,6 @@ class LIBCANVAS_API WaveViewCache
*/ */
typedef std::pair<boost::shared_ptr<ARDOUR::AudioSource>,boost::shared_ptr<Entry> > ListEntry; typedef std::pair<boost::shared_ptr<ARDOUR::AudioSource>,boost::shared_ptr<Entry> > ListEntry;
typedef std::vector<ListEntry> CacheList; typedef std::vector<ListEntry> CacheList;
CacheList cache_list;
struct SortByTimestamp { struct SortByTimestamp {
bool operator() (const WaveViewCache::ListEntry& a, const WaveViewCache::ListEntry& b) { bool operator() (const WaveViewCache::ListEntry& a, const WaveViewCache::ListEntry& b) {

View File

@ -1704,7 +1704,6 @@ WaveViewCache::add (boost::shared_ptr<ARDOUR::AudioSource> src, boost::shared_pt
ce->timestamp = g_get_monotonic_time (); ce->timestamp = g_get_monotonic_time ();
cache_map[src].push_back (ce); cache_map[src].push_back (ce);
cache_list.push_back (make_pair (src, ce));
} }
uint64_t uint64_t
@ -1730,10 +1729,18 @@ WaveViewCache::cache_full()
void void
WaveViewCache::cache_flush () WaveViewCache::cache_flush ()
{ {
SortByTimestamp sorter; /* Build a sortable list of all cache entries */
CacheList cache_list;
for (ImageCache::const_iterator cm = cache_map.begin(); cm != cache_map.end(); ++cm) {
for (CacheLine::const_iterator cl = cm->second.begin(); cl != cm->second.end(); ++cl) {
cache_list.push_back (make_pair (cm->first, *cl));
}
}
/* sort list in LRU order */ /* sort list in LRU order */
SortByTimestamp sorter;
sort (cache_list.begin(), cache_list.end(), sorter); sort (cache_list.begin(), cache_list.end(), sorter);
while (image_cache_size > _image_cache_threshold && !cache_map.empty() && !cache_list.empty()) { while (image_cache_size > _image_cache_threshold && !cache_map.empty() && !cache_list.empty()) {