Home | History | Annotate | Download | only in linux

Lines Matching defs:kref

1 /*	$NetBSD: kref.h,v 1.14 2023/02/24 11:02:06 riastradh Exp $	*/
44 struct kref {
49 kref_init(struct kref *kref)
51 atomic_store_relaxed(&kref->kr_count, 1);
55 kref_get(struct kref *kref)
58 atomic_inc_uint_nv(&kref->kr_count);
60 KASSERTMSG((count > 1), "getting released kref");
64 kref_get_unless_zero(struct kref *kref)
69 count = atomic_load_relaxed(&kref->kr_count);
72 } while (atomic_cas_uint(&kref->kr_count, count, (count + 1)) !=
79 kref_sub(struct kref *kref, unsigned int count, void (*release)(struct kref *))
86 old = atomic_load_relaxed(&kref->kr_count);
87 KASSERTMSG((count <= old), "overreleasing kref: %u - %u",
90 } while (atomic_cas_uint(&kref->kr_count, old, new) != old);
94 (*release)(kref);
102 kref_put_lock(struct kref *kref, void (*release)(struct kref *),
110 old = atomic_load_relaxed(&kref->kr_count);
114 if (atomic_add_int_nv(&kref->kr_count, -1) == 0) {
116 (*release)(kref);
123 } while (atomic_cas_uint(&kref->kr_count, old, new) != old);
129 kref_put(struct kref *kref, void (*release)(struct kref *))
132 return kref_sub(kref, 1, release);
136 kref_put_mutex(struct kref *kref, void (*release)(struct kref *),
144 old = atomic_load_relaxed(&kref->kr_count);
148 if (atomic_add_int_nv(&kref->kr_count, -1) == 0) {
150 (*release)(kref);
157 } while (atomic_cas_uint(&kref->kr_count, old, new) != old);
163 kref_read(const struct kref *kref)
166 return atomic_load_relaxed(&kref->kr_count);
174 kref_referenced_p(struct kref *kref)
177 return (0 < kref->kr_count);
181 kref_exclusive_p(struct kref *kref)
184 KASSERT(0 < kref->kr_count);
185 return (kref->kr_count == 1);