Lines Matching refs:parman
44 int (*item_add)(struct parman *parman, struct parman_prio *prio,
46 void (*item_remove)(struct parman *parman, struct parman_prio *prio,
50 struct parman { struct
59 static int parman_enlarge(struct parman *parman) in parman_enlarge() argument
61 unsigned long new_count = parman->limit_count + in parman_enlarge()
62 parman->ops->resize_step; in parman_enlarge()
65 err = parman->ops->resize(parman->priv, new_count); in parman_enlarge()
68 parman->limit_count = new_count; in parman_enlarge()
72 static int parman_shrink(struct parman *parman) in parman_shrink() argument
74 unsigned long new_count = parman->limit_count - in parman_shrink()
75 parman->ops->resize_step; in parman_shrink()
78 if (new_count < parman->ops->base_count) in parman_shrink()
80 err = parman->ops->resize(parman->priv, new_count); in parman_shrink()
83 parman->limit_count = new_count; in parman_shrink()
115 static unsigned long parman_lsort_new_index_find(struct parman *parman, in parman_lsort_new_index_find() argument
118 list_for_each_entry_from_reverse(prio, &parman->prio_list, list) { in parman_lsort_new_index_find()
126 static void __parman_prio_move(struct parman *parman, struct parman_prio *prio, in __parman_prio_move() argument
130 parman->ops->move(parman->priv, item->index, to_index, count); in __parman_prio_move()
133 static void parman_prio_shift_down(struct parman *parman, in parman_prio_shift_down() argument
143 __parman_prio_move(parman, prio, item, to_index, 1); in parman_prio_shift_down()
148 static void parman_prio_shift_up(struct parman *parman, in parman_prio_shift_up() argument
158 __parman_prio_move(parman, prio, item, to_index, 1); in parman_prio_shift_up()
163 static void parman_prio_item_remove(struct parman *parman, in parman_prio_item_remove() argument
176 __parman_prio_move(parman, prio, last_item, to_index, 1); in parman_prio_item_remove()
182 static int parman_lsort_item_add(struct parman *parman, in parman_lsort_item_add() argument
190 if (parman->count + 1 > parman->limit_count) { in parman_lsort_item_add()
191 err = parman_enlarge(parman); in parman_lsort_item_add()
196 new_index = parman_lsort_new_index_find(parman, prio); in parman_lsort_item_add()
197 list_for_each_entry_reverse(prio2, &parman->prio_list, list) { in parman_lsort_item_add()
200 parman_prio_shift_down(parman, prio2); in parman_lsort_item_add()
204 parman->count++; in parman_lsort_item_add()
208 static void parman_lsort_item_remove(struct parman *parman, in parman_lsort_item_remove() argument
212 parman_prio_item_remove(parman, prio, item); in parman_lsort_item_remove()
213 list_for_each_entry_continue(prio, &parman->prio_list, list) in parman_lsort_item_remove()
214 parman_prio_shift_up(parman, prio); in parman_lsort_item_remove()
215 parman->count--; in parman_lsort_item_remove()
216 if (parman->limit_count - parman->count >= parman->ops->resize_step) in parman_lsort_item_remove()
217 parman_shrink(parman); in parman_lsort_item_remove()
268 struct parman *parman_create(const struct parman_ops *ops, void *priv) in parman_create()
270 struct parman *parman; in parman_create() local
272 parman = kzalloc(sizeof(*parman), GFP_KERNEL); in parman_create()
273 if (!parman) in parman_create()
275 INIT_LIST_HEAD(&parman->prio_list); in parman_create()
276 parman->ops = ops; in parman_create()
277 parman->priv = priv; in parman_create()
278 parman->limit_count = ops->base_count; in parman_create()
279 parman->algo = parman_algos[ops->algo]; in parman_create()
280 return parman; in parman_create()
290 void parman_destroy(struct parman *parman) in parman_destroy() argument
292 WARN_ON(!list_empty(&parman->prio_list)); in parman_destroy()
293 kfree(parman); in parman_destroy()
308 void parman_prio_init(struct parman *parman, struct parman_prio *prio, in parman_prio_init() argument
318 list_for_each(pos, &parman->prio_list) { in parman_prio_init()
352 int parman_item_add(struct parman *parman, struct parman_prio *prio, in parman_item_add() argument
355 return parman->algo->item_add(parman, prio, item); in parman_item_add()
367 void parman_item_remove(struct parman *parman, struct parman_prio *prio, in parman_item_remove() argument
370 parman->algo->item_remove(parman, prio, item); in parman_item_remove()