Lines Matching full:rc
66 zfs_refcount_create(zfs_refcount_t *rc)
68 mutex_init(&rc->rc_mtx, NULL, MUTEX_DEFAULT, NULL);
69 avl_create(&rc->rc_tree, zfs_refcount_compare, sizeof (reference_t),
71 list_create(&rc->rc_removed, sizeof (reference_t),
73 rc->rc_count = 0;
74 rc->rc_removed_count = 0;
75 rc->rc_tracked = reference_tracking_enable;
79 zfs_refcount_create_tracked(zfs_refcount_t *rc)
81 zfs_refcount_create(rc);
82 rc->rc_tracked = B_TRUE;
86 zfs_refcount_create_untracked(zfs_refcount_t *rc)
88 zfs_refcount_create(rc);
89 rc->rc_tracked = B_FALSE;
93 zfs_refcount_destroy_many(zfs_refcount_t *rc, uint64_t number)
98 ASSERT3U(rc->rc_count, ==, number);
99 while ((ref = avl_destroy_nodes(&rc->rc_tree, &cookie)) != NULL)
101 avl_destroy(&rc->rc_tree);
103 while ((ref = list_remove_head(&rc->rc_removed)))
105 list_destroy(&rc->rc_removed);
106 mutex_destroy(&rc->rc_mtx);
110 zfs_refcount_destroy(zfs_refcount_t *rc)
112 zfs_refcount_destroy_many(rc, 0);
116 zfs_refcount_is_zero(zfs_refcount_t *rc)
118 return (zfs_refcount_count(rc) == 0);
122 zfs_refcount_count(zfs_refcount_t *rc)
124 return (atomic_load_64(&rc->rc_count));
128 zfs_refcount_add_many(zfs_refcount_t *rc, uint64_t number, const void *holder)
133 if (likely(!rc->rc_tracked)) {
134 count = atomic_add_64_nv(&(rc)->rc_count, number);
143 mutex_enter(&rc->rc_mtx);
144 avl_add(&rc->rc_tree, ref);
145 rc->rc_count += number;
146 count = rc->rc_count;
147 mutex_exit(&rc->rc_mtx);
153 zfs_refcount_add(zfs_refcount_t *rc, const void *holder)
155 return (zfs_refcount_add_many(rc, 1, holder));
159 zfs_refcount_add_few(zfs_refcount_t *rc, uint64_t number, const void *holder)
161 if (likely(!rc->rc_tracked))
162 (void) zfs_refcount_add_many(rc, number, holder);
164 (void) zfs_refcount_add(rc, holder);
168 zfs_refcount_remove_many(zfs_refcount_t *rc, uint64_t number,
174 if (likely(!rc->rc_tracked)) {
175 count = atomic_add_64_nv(&(rc)->rc_count, -number);
183 mutex_enter(&rc->rc_mtx);
184 ASSERT3U(rc->rc_count, >=, number);
185 ref = avl_find(&rc->rc_tree, &s, NULL);
188 (u_longlong_t)(uintptr_t)rc);
191 avl_remove(&rc->rc_tree, ref);
193 list_insert_head(&rc->rc_removed, ref);
194 if (rc->rc_removed_count >= reference_history) {
195 ref = list_remove_tail(&rc->rc_removed);
198 rc->rc_removed_count++;
203 rc->rc_count -= number;
204 count = rc->rc_count;
205 mutex_exit(&rc->rc_mtx);
210 zfs_refcount_remove(zfs_refcount_t *rc, const void *holder)
212 return (zfs_refcount_remove_many(rc, 1, holder));
216 zfs_refcount_remove_few(zfs_refcount_t *rc, uint64_t number, const void *holder)
218 if (likely(!rc->rc_tracked))
219 (void) zfs_refcount_remove_many(rc, number, holder);
221 (void) zfs_refcount_remove(rc, holder);
263 zfs_refcount_transfer_ownership_many(zfs_refcount_t *rc, uint64_t number,
268 if (likely(!rc->rc_tracked))
274 mutex_enter(&rc->rc_mtx);
275 ref = avl_find(&rc->rc_tree, &s, NULL);
278 avl_update(&rc->rc_tree, ref);
279 mutex_exit(&rc->rc_mtx);
283 zfs_refcount_transfer_ownership(zfs_refcount_t *rc, const void *current_holder,
286 return (zfs_refcount_transfer_ownership_many(rc, 1, current_holder,
296 zfs_refcount_held(zfs_refcount_t *rc, const void *holder)
302 if (likely(!rc->rc_tracked))
303 return (zfs_refcount_count(rc) > 0);
308 mutex_enter(&rc->rc_mtx);
309 ref = avl_find(&rc->rc_tree, &s, &idx);
311 ref = avl_nearest(&rc->rc_tree, idx, AVL_AFTER);
313 mutex_exit(&rc->rc_mtx);
323 zfs_refcount_not_held(zfs_refcount_t *rc, const void *holder)
329 if (likely(!rc->rc_tracked))
332 mutex_enter(&rc->rc_mtx);
336 ref = avl_find(&rc->rc_tree, &s, &idx);
338 ref = avl_nearest(&rc->rc_tree, idx, AVL_AFTER);
340 mutex_exit(&rc->rc_mtx);