Exemplo n.º 1
0
Arquivo: dict.c Projeto: HarmtH/vim
/*
 * Free a Dictionary, including all non-container items it contains.
 * Ignores the reference count.
 */
    static void
dict_free_contents(dict_T *d)
{
    int		todo;
    hashitem_T	*hi;
    dictitem_T	*di;

    /* Lock the hashtab, we don't want it to resize while freeing items. */
    hash_lock(&d->dv_hashtab);
    todo = (int)d->dv_hashtab.ht_used;
    for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi)
    {
	if (!HASHITEM_EMPTY(hi))
	{
	    /* Remove the item before deleting it, just in case there is
	     * something recursive causing trouble. */
	    di = HI2DI(hi);
	    hash_remove(&d->dv_hashtab, hi);
	    clear_tv(&di->di_tv);
	    vim_free(di);
	    --todo;
	}
    }
    hash_clear(&d->dv_hashtab);
}
Exemplo n.º 2
0
int
stm_hashtable_insert(char *name, struct hashtable *h, unsigned long *k, unsigned long *v,unsigned long v_size){ 
	unsigned int index ; 	
        struct entry * e;
        hash_lock() ;
        e = (struct entry *)pos_malloc( name , sizeof(struct entry)) ;
        if( e == NULL) PR_DEBUG("enull\n") ;
        e->v = (unsigned long *)pos_malloc( name , v_size) ;

//	TM_START(1, RW) ; 	
        if( e->v == NULL)PR_DEBUG("e->v null\n") ;
        hash_unlock() ;
	
	TM_START(1, RW) ; 		

//        e->h = hash(h , k) ;
//        memcpy(e->k , k , sizeof(unsigned long)*KEY_SIZE) ;
//        memcpy(e->v , v, v_size) ;
	TM_STORE(&e->h , hash(h,k)) ; 	
	TM_STORE(&e->k , k ) ; 	
	TM_STORE(&e->v , v ) ;
//        TM_START(1 , RW) ;
                int entrycount = (int)TM_LOAD(&h->entrycount) ;
                int loadlimit = (int)TM_LOAD(&h->loadlimit) ;
                TM_STORE(&h->entrycount , entrycount+1) ;
                if( entrycount+1 > loadlimit ){
//                      h_lock();
//                      shashtable_expand(name ,h) ;   
//                      h_unlock() ;    
                }
                e->h = hash( h , k ) ;
                index = indexFor((int)TM_LOAD(&h->tablelength) , e->h);
                e->next = (struct entry *)TM_LOAD(&h->table[index]);
                pos_clflush_cache_range(e , sizeof(struct entry));
                pos_clflush_cache_range(e->v , v_size) ;
                TM_STORE(&h->table[index] , e) ;
                pos_clflush_cache_range(&h->table[index] , sizeof(unsigned long)) ;
        TM_COMMIT ;
        return ;

}