static int _kmem_free_obj(struct kmem_cache_t *cachep, void *objp) { if(cachep == NULL || objp == NULL) return -1; /*unsigned long address = ((unsigned long )objp & (~(DEFAULT_SLAB_PAGES * PAGE_SIZE) + 1));*/ unsigned long address = ((unsigned long )objp & VALUE_MASK(DEFAULT_SLAB_PAGES * PAGE_SIZE)); struct slab *slabp = (struct slab *)address; /*printf("slabp = %x.\n",slabp);*/ return slab_free_obj(cachep,slabp,objp); }
static int _kmem_free_obj(kmem_cache_t *cachep, void *objp) { if(cachep == NULL || objp == NULL) { return -1; } unsigned long address = ((unsigned long )objp & VALUE_MASK(DEFAULT_SLAB_PAGES * PAGE_SIZE)); struct slab *slabp = (struct slab *)address; return slab_free_obj(cachep,slabp,objp); }
/* Free an element in the hash table */ int ht_free(struct hashtable *t, unsigned int index) { if (index >= t->size) return HT_IOVERFLOW; /* Index overflow */ /* ht_free() calls against non-existent elements are ignored */ if (t->table[index] != NULL && t->table[index] != ht_free_element) { /* release the key */ if (t->key_destructor) t->key_destructor(t->table[index]->key); /* release the value */ if (t->val_destructor) t->val_destructor(t->table[index]->data); /* free the element structure */ #ifdef AHT_USE_SLAB slab_free_obj(t->cache, t->table[index]); #else free(t->table[index]); #endif /* AHT_USE_SLAB */ /* mark the element as freed */ t->table[index] = ht_free_element; t->used--; } return HT_OK; }