Changeset View
Changeset View
Standalone View
Standalone View
head/sys/sys/refcount.h
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
static __inline void | static __inline void | ||||
refcount_acquire(volatile u_int *count) | refcount_acquire(volatile u_int *count) | ||||
{ | { | ||||
KASSERT(*count < UINT_MAX, ("refcount %p overflowed", count)); | KASSERT(*count < UINT_MAX, ("refcount %p overflowed", count)); | ||||
atomic_add_int(count, 1); | atomic_add_int(count, 1); | ||||
} | } | ||||
static __inline __result_use_check bool | |||||
refcount_acquire_checked(volatile u_int *count) | |||||
{ | |||||
u_int lcount; | |||||
for (lcount = *count;;) { | |||||
if (__predict_false(lcount + 1 < lcount)) | |||||
return (false); | |||||
if (__predict_true(atomic_fcmpset_int(count, &lcount, | |||||
lcount + 1) == 1)) | |||||
return (true); | |||||
} | |||||
} | |||||
static __inline int | static __inline int | ||||
refcount_release(volatile u_int *count) | refcount_release(volatile u_int *count) | ||||
{ | { | ||||
u_int old; | u_int old; | ||||
atomic_thread_fence_rel(); | atomic_thread_fence_rel(); | ||||
old = atomic_fetchadd_int(count, -1); | old = atomic_fetchadd_int(count, -1); | ||||
KASSERT(old > 0, ("refcount %p is zero", count)); | KASSERT(old > 0, ("refcount %p is zero", count)); | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |