示例#1
0
static void update_lru(struct ZSTLMap *pm, ZSTLMapEntry_t *pme)
{
    //  remove pme from list
    remove_lru(pm, pme);
    //  insert_lru(pm, pme)
    insert_lru(pm, pme);
}
示例#2
0
static inline void update_lru(struct dir_cache_entry * de)
{
	if (de == *de->lru_head)
		*de->lru_head = de->next_lru;
	else {
		remove_lru(de);
		add_lru(de,*de->lru_head);
	}
}
示例#3
0
/*   Return 0 if succeeds, 1 if object doesn't exist.
 */
int ZSTLMapDelete(struct ZSTLMap *pm, char *key, uint32_t keylen)
{
    uint64_t            h;
    ZSTLMapEntry_t   **ppme;
    ZSTLMapEntry_t    *pme;
    ZSTLMapBucket_t   *pb;
    char               *key2;

    key2 = (char *) *((uint64_t *) key);

    do_lock(&(pm->mutex));

    #ifdef SANDISK_PRINTSTUFF
	fprintf(stderr, "ZSTLMapDelete: pm=%p, key=0x%lx, keylen=%d\n", pm, *((uint64_t *) key), keylen);
    #endif

    h = zs_hash((const unsigned char *) key, sizeof(uint64_t), 0) % pm->nbuckets;
    pb = &(pm->buckets[h]);

    zstlmap_assert(keylen == 8); // remove this! xxxzzz

    for (ppme = &(pb->entry); (*ppme) != NULL; ppme = &((*ppme)->next)) {
	pme = *ppme;
	if (pme->key == key2) {

	    //  Remove from the LRU list if necessary
	    remove_lru(pm, pme);
	    pm->n_entries--;

            *ppme = pme->next;
            free_pme(pm, pme);
	    do_unlock(&(pm->mutex));
            return (0);
        }
    }
    do_unlock(&(pm->mutex));
    return (1);
}
示例#4
0
static void replace_lru(struct ZSTLMap *pm, ZSTLMapEntry_t *pme_in)
{
    ZSTLMapEntry_t **ppme;
    ZSTLMapEntry_t  *pme;
    int               found_it;

    for (pme=pm->lru_tail; pme != NULL; pme = pme->prev_lru) {
        zstlmap_assert(pme->refcnt >= 0); // xxxzzz remove this!
        if ((pme->refcnt == 0) && (pme != pme_in)) {
	    break;
	}
    }
    if (pme == NULL) {
	fprintf(stderr, "replace_lru could not find a victim!!!!\n");
	zstlmap_assert(0);
    }
    #ifdef SANDISK_PRINTSTUFF
	fprintf(stderr, "replace_lru found a victim: %p\n", pme);
    #endif

    //  Remove from bucket list
    found_it = 0;
    for (ppme = &(pme->bucket->entry); (*ppme) != NULL; ppme = &((*ppme)->next)) {
	if (pme == (*ppme)) {
	    *ppme = pme->next;
	    found_it = 1;
	    break;
	}
    }
    zstlmap_assert(found_it);

    remove_lru(pm, pme);
    pm->n_entries--;
    (pm->replacement_callback)(pm->replacement_callback_data, pme->key, pme->keylen, pme->contents, pme->datalen);
    free_pme(pm, pme);

}
示例#5
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();
 }