Exemplo n.º 1
0
/* Expires all the mac-learning entries in 'ml'.  The tags in 'ml' are
 * discarded, so the client is responsible for revalidating any flows that
 * depend on 'ml', if necessary. */
void
mac_learning_flush(struct mac_learning *ml)
{
    struct mac_entry *e;
    while (get_lru(ml, &e)){
        free_mac_entry(ml, e);
    }
}
Exemplo n.º 2
0
	int Cache::free_some_lru()
	{
		/*
		 * this triggering deletion (and memory freeying) of cached elements
		 * (yes, it is a sort of garbage collector, with its pros and cons)
		 */
		if ( cached_elements() < 1 ) return 0;
		return erase( get_lru()  );
	}
Exemplo n.º 3
0
void
mac_learning_run(struct mac_learning *ml, struct tag_set *set)
{
    struct mac_entry *e;
    while (get_lru(ml, &e) && time_now() >= e->expires) {
        COVERAGE_INC(mac_learning_expired);
        if (set) {
            tag_set_add(set, e->tag);
        }
        free_mac_entry(ml, e);
    }
}
Exemplo n.º 4
0
	bool Cache::freeCachedImage(Image *image)
	{
		/*
		 * if the supplied image is cached as a master image of a clone, it is freed and deregistered.
		 * if not, no action is performed.
		 * */
		// WARNING : FIXME : DANGER !!
		if( !image )return false;
//		if( is_in_cache(image) && usageCounter[image->getKey()]==1 )
		if( is_in_clone_cache(image) )
		{
			usageCounter[image->getKey()]--;
			erase_clone(image);	// we _always_ immediately delete clones
			setGlobalVariable(FIM_VID_CACHE_STATUS,getReport().c_str());
			return true;
		}
		else
		if( is_in_cache(image) )
		{
			usageCounter[image->getKey()]--;
			if(
				(usageCounter[image->getKey()])==0 && 
				image->getKey().second!=FIM_E_STDIN 
				)
			{
#if 0
				if( need_free() && image->getKey().second!=FIM_E_STDIN )
				{
					cache_key_t key = image->getKey();
					this->erase( image );
					usageCounter.erase(key);
				}
#else
				/* doing it here is dangerous : */
				if( need_free() )
				{
					Image * lrui = get_lru(true);
					if(lrui && ( lrui->getKey().second!=FIM_E_STDIN ))
					{	
						cache_key_t key = lrui->getKey();
						this->erase( lrui );
						usageCounter.erase(key);
					}
						// missing usageCounter.erase()..
				}
#endif
			}
			setGlobalVariable(FIM_VID_CACHE_STATUS,getReport().c_str());
			return true;
		}
		return false;
	}
Exemplo n.º 5
0
void
FileRecordNumber :: add_lru( frn_record * x )
{
    if ( x->locked == 0 )
    {
        printf( "FileRecordNumber: unlocking a record "
                "already unlocked %s:%d\n",
                __FILE__, __LINE__ );
        return;
    }

    if ( cache_size == max_cache_size )
    {
        bool needsflush = false;
        frn_record * y = get_lru();
        if ( y->dirty )
        {
            needsflush = true;
            flushes++;
            __put_record( y );
        }
        del_hash( y );
        delete y;
        if ( needsflush )
            flushes = flush();
    }

    cache_size++;
    x->locked = 0;

    if ( lru_tail == NULL )
    {
        lru_head = lru_tail = x;
        x->lru_next = x->lru_prev = NULL;
    }
    else
    {
        x->lru_prev = lru_tail;
        x->lru_prev->lru_next = x;
        x->lru_next = NULL;
        lru_tail = x;
    }
}