Data *data;
};
+// An LRU cache which can take a 'snapshot' of its current state. This is useful
+// for allowing concurrent read access without requiring a mutex to be locked.
template<class Key, class Data, class Hasher = std::hash<Key>>
-class LRUConstCache : public LRUCache<Key, Data>
+class LRUSnapshotCache : public LRUCache<Key, Data>
{
using LRUBase = LRUCache<Key, Data>;
public:
- LRUConstCache(int n)
+ LRUSnapshotCache(int n)
: LRUBase(n)
{}
- ~LRUConstCache() { clearConstCache(); }
+ ~LRUSnapshotCache() { clearSnapshot(); }
Data add(const Key &key, const Data &data) override
{
- constCacheNeedsUpdate = true;
+ snapshotNeedsUpdate = true;
return LRUBase::add(key, data);
}
- void updateConstCache();
- const Data &queryConstCache(const Key &key) const;
+ void updateSnapshot();
+ const Data &querySnapshot(const Key &key) const;
private:
- void clearConstCache();
- bool constCacheNeedsUpdate = false;
- std::unordered_map<Key, Data, Hasher> constCache;
+ void clearSnapshot();
+ bool snapshotNeedsUpdate = false;
+ std::unordered_map<Key, Data, Hasher> snapshot;
};
} // namespace sw
}
template<class Key, class Data, class Hasher>
-void LRUConstCache<Key, Data, Hasher>::clearConstCache()
+void LRUSnapshotCache<Key, Data, Hasher>::clearSnapshot()
{
- constCache.clear();
+ snapshot.clear();
}
template<class Key, class Data, class Hasher>
-void LRUConstCache<Key, Data, Hasher>::updateConstCache()
+void LRUSnapshotCache<Key, Data, Hasher>::updateSnapshot()
{
- if(constCacheNeedsUpdate)
+ if(snapshotNeedsUpdate)
{
- clearConstCache();
+ clearSnapshot();
for(int i = 0; i < LRUBase::size; i++)
{
if(LRUBase::data[i])
{
- constCache[*LRUBase::ref[i]] = LRUBase::data[i];
+ snapshot[*LRUBase::ref[i]] = LRUBase::data[i];
}
}
- constCacheNeedsUpdate = false;
+ snapshotNeedsUpdate = false;
}
}
template<class Key, class Data, class Hasher>
-const Data &LRUConstCache<Key, Data, Hasher>::queryConstCache(const Key &key) const
+const Data &LRUSnapshotCache<Key, Data, Hasher>::querySnapshot(const Key &key) const
{
- auto it = constCache.find(key);
+ auto it = snapshot.find(key);
static Data null = {};
- return (it != constCache.end()) ? it->second : null;
+ return (it != snapshot.end()) ? it->second : null;
}
} // namespace sw
cache.add(key, routine);
}
-rr::Routine *Device::SamplingRoutineCache::queryConst(const vk::Device::SamplingRoutineCache::Key &key) const
+rr::Routine *Device::SamplingRoutineCache::querySnapshot(const vk::Device::SamplingRoutineCache::Key &key) const
{
- return cache.queryConstCache(key).get();
+ return cache.querySnapshot(key).get();
}
-void Device::SamplingRoutineCache::updateConstCache()
+void Device::SamplingRoutineCache::updateSnapshot()
{
- cache.updateConstCache();
+ cache.updateSnapshot();
}
Device::SamplerIndexer::~SamplerIndexer()
return samplingRoutineCache.get();
}
-rr::Routine *Device::findInConstCache(const SamplingRoutineCache::Key &key) const
+rr::Routine *Device::querySnapshotCache(const SamplingRoutineCache::Key &key) const
{
- return samplingRoutineCache->queryConst(key);
+ return samplingRoutineCache->querySnapshot(key);
}
-void Device::updateSamplingRoutineConstCache()
+void Device::updateSamplingRoutineSnapshotCache()
{
std::unique_lock<std::mutex> lock(samplingRoutineCacheMutex);
- samplingRoutineCache->updateConstCache();
+ samplingRoutineCache->updateSnapshot();
}
std::mutex &Device::getSamplingRoutineCacheMutex()
std::shared_ptr<rr::Routine> query(const Key &key) const;
void add(const Key &key, const std::shared_ptr<rr::Routine> &routine);
- rr::Routine *queryConst(const Key &key) const;
- void updateConstCache();
+ rr::Routine *querySnapshot(const Key &key) const;
+ void updateSnapshot();
private:
- sw::LRUConstCache<Key, std::shared_ptr<rr::Routine>, Key::Hash> cache;
+ sw::LRUSnapshotCache<Key, std::shared_ptr<rr::Routine>, Key::Hash> cache;
};
SamplingRoutineCache *getSamplingRoutineCache() const;
std::mutex &getSamplingRoutineCacheMutex();
- rr::Routine *findInConstCache(const SamplingRoutineCache::Key &key) const;
- void updateSamplingRoutineConstCache();
+ rr::Routine *querySnapshotCache(const SamplingRoutineCache::Key &key) const;
+ void updateSamplingRoutineSnapshotCache();
class SamplerIndexer
{