diff --git a/sys/sys/refcount.h b/sys/sys/refcount.h index 9788fdfeaa44..d15dbe08a7db 100644 --- a/sys/sys/refcount.h +++ b/sys/sys/refcount.h @@ -32,6 +32,15 @@ #ifndef __SYS_REFCOUNT_H__ #define __SYS_REFCOUNT_H__ +#include + +#ifdef _KERNEL +#warning _KERNEL defined +#include +#else +#define KASSERT(exp, msg) /* */ +#endif + static __inline void refcount_init(volatile u_int *count, u_int value) { @@ -49,8 +58,12 @@ refcount_acquire(volatile u_int *count) static __inline int refcount_release(volatile u_int *count) { + u_int old; - return (atomic_fetchadd_int(count, -1) == 1); + /* XXX: Should this have a rel membar? */ + old = atomic_fetchadd_int(count, -1); + KASSERT(old > 0, ("negative refcount %p", count)); + return (old == 1); } #endif /* ! __SYS_REFCOUNT_H__ */