void * slab_get_obj(struct kmem_cache_t *cachep, struct slab *slabp) { if(cachep == NULL || slabp == NULL) return NULL; struct list_head *item = NULL; if(slabp->free == BUFCTL_END) { printf("not free obj."); return NULL; } void *objp = index_to_obj(cachep, slabp, slabp->free); unsigned int next = slab_bufctl(slabp)[slabp->free]; /*printf("next = %d",next);*/ slabp->inuse++; slabp->free = next; /* move to the full list*/ if(slabp->inuse == cachep->obj_num) { item = &(slabp->list); list_del(item); list_add(item, &(cachep->lists.full)); } return objp; }
static void * slab_get_obj(kmem_cache_t *cachep, struct slab *slabp) { if(cachep == NULL || slabp == NULL) { return NULL; } struct list_head *item = NULL; if(slabp->free == BUFCTL_END) { DD("not free obj."); return NULL; } void *objp = index_to_obj(cachep, slabp, slabp->free); uint32_t next = slab_bufctl(slabp)[slabp->free]; inc_slab_use(slabp); set_slab_free(slabp, next); /* move to the full list*/ if(slabp->inuse == cachep->obj_num) { item = &(slabp->list); list_del(item); list_add(item, &(cachep->kmem_lists.full)); } dec_cache_free(cachep); return objp; }