Changeset View
Changeset View
Standalone View
Standalone View
sys/sys/refcount.h
Show First 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | refcount_release_if_gt(volatile u_int *count, u_int n) | ||||
KASSERT(n > 0, | KASSERT(n > 0, | ||||
("refcount_release_if_gt: Use refcount_release for final ref")); | ("refcount_release_if_gt: Use refcount_release for final ref")); | ||||
old = *count; | old = *count; | ||||
for (;;) { | for (;;) { | ||||
if (REFCOUNT_COUNT(old) <= n) | if (REFCOUNT_COUNT(old) <= n) | ||||
return (false); | return (false); | ||||
if (__predict_false(REFCOUNT_SATURATED(old))) | if (__predict_false(REFCOUNT_SATURATED(old))) | ||||
return (true); | return (true); | ||||
if (atomic_fcmpset_int(count, &old, old - 1)) | if (atomic_fcmpset_rel_int(count, &old, old - 1)) | ||||
return (true); | return (true); | ||||
} | } | ||||
} | } | ||||
static __inline __result_use_check bool | static __inline __result_use_check bool | ||||
refcount_release_if_not_last(volatile u_int *count) | refcount_release_if_not_last(volatile u_int *count) | ||||
{ | { | ||||
return refcount_release_if_gt(count, 1); | return refcount_release_if_gt(count, 1); | ||||
} | } | ||||
#endif /* ! __SYS_REFCOUNT_H__ */ | #endif /* ! __SYS_REFCOUNT_H__ */ |