From 75f31a5fe476496886feea70e8c69930080d2690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Wed, 23 Jul 2008 16:40:07 +0000 Subject: [PATCH] pjd@'s r180759 was intended to revert r180755 due to ipfilter breakage, but removed too much, breaking the build in other places instead. Now that the ipfilter issue has been fixed (or hacked around), address the second issue by restoring r180755, with one small change. I don't feel comfortable using assert(3) in a header that will be included in userland code that may or may not already have an assertion mechanism in place, so KASSERT() evaluates to a no-op in the !_KERNEL case. --- sys/sys/refcount.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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__ */