示例#1
0
 /// Removes the least recently used element from the cache
 void remove_lru() const{
   cachelock.lock();
   KeyType keytoerase = lruage.back().key;
   // is the key I am invalidating in the cache?
   typename cache_type::iterator i = cache.find(keytoerase);
   if (i != cache.end()) {
     // drop it from the lru list
     delete i->second;
     cache.erase(i);
   }
   cachelock.unlock();
 }
示例#2
0
inline cusparseHandle_t cusparse_handle(const command_queue &q) {
    typedef std::shared_ptr<std::remove_pointer<cusparseHandle_t>::type> smart_handle;
    typedef vex::detail::object_cache<vex::detail::index_by_context, smart_handle> cache_type;

    static cache_type cache;

    auto h = cache.find(q);

    if (h == cache.end()) {
        select_context(q);
        cusparseHandle_t handle;
        cuda_check( cusparseCreate(&handle) );
        cuda_check( cusparseSetStream(handle, q.raw()) );

        h = cache.insert(q, smart_handle(handle, detail::deleter()));
    }

    return h->second.get();
}
示例#3
0
 /// Updates the cache with this new value
 void update_cache(const KeyType &key, const ValueType &val) const{
   cachelock.lock();
   typename cache_type::iterator i = cache.find(key);
   // create a new entry
   if (i == cache.end()) {
     cachelock.unlock();
     // if we are out of room, remove the lru entry
     if (cache.size() >= maxcache) remove_lru();
     cachelock.lock();
     // insert the element, remember the iterator so we can push it
     // straight to the LRU list
     std::pair<typename cache_type::iterator, bool> ret = cache.insert(std::make_pair(key, new lru_entry_type(key, val)));
     if (ret.second)  lruage.push_front(*(ret.first->second));
   }
   else {
     // modify entry in place
     i->second->value = val;
     // swap to front of list
     //boost::swap_nodes(lru_list_type::s_iterator_to(i->second), lruage.begin());
     lruage.erase(lru_list_type::s_iterator_to(*(i->second)));
     lruage.push_front(*(i->second));
   }
   cachelock.unlock();
 }
示例#4
0
bool locator::in_cache(cache_type<T> &cache) const
{
	return index_ < 0 ? false : cache.get_element(index_).loaded;
}
示例#5
0
void locator::add_to_cache(cache_type<T> &cache, const T &data) const
{
	if (index_ >= 0)
		cache.get_element(index_) = cache_item<T>(data);
}
示例#6
0
void locator::add_to_cache(cache_type<T> &cache, const T &data) const
{
	cache.add(data, hash_, hash1_);
}