idr_destroy
void idr_destroy(struct idr *idp) { while (idp->id_free_cnt) { struct idr_layer *p = get_from_free_list(idp); kmem_cache_free(idr_layer_cache, p); } } EXPORT_SYMBOL(idr_destroy);七.用法
1.api函数
void *idr_find(struct idr *idp, int id); //查找id对应的指针 int idr_pre_get(struct idr *idp, gfp_t gfp_mask); //分配idr_layer空闲链表 int idr_get_new(struct idr *idp, void *ptr, int *id); //获取id,捆绑指针ptr int idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id); //起始数值获取id,捆绑指针ptr int idr_for_each(struct idr *idp,int (*fn)(int id, void *p, void *data), void *data); void *idr_get_next(struct idr *idp, int *nextid); void *idr_replace(struct idr *idp, void *ptr, int id); //替换id捆绑的指针 void idr_remove(struct idr *idp, int id); //移除id void idr_remove_all(struct idr *idp); //移除所有id void idr_destroy(struct idr *idp); //销毁idr_layer空闲链表 void idr_init(struct idr *idp); //初始化idr2.大致用法
1.idr_init声明设置idr
2.idr_pre_get分配空闲idr_layer链表
3.id_get_new/idr_get_new_above分配id并将id与指针ptr捆绑
4.利用idr_find根据id获取指针ptr
5.idr_remove/idr_remove_all移除分配的id
6.idr_destroy销毁空闲idr_layer链表
7.idr_replace替换id