summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2008-07-23 16:40:07 +0000
committerdes <des@FreeBSD.org>2008-07-23 16:40:07 +0000
commit3bf9afd822b8f7b896bd5095278e55d59773cd8a (patch)
treefee6bb026ba92220669b63ed2527100ab8605599
parent4cb5c186306c78d07df0b8ee48509ec2e346f3ef (diff)
downloadFreeBSD-src-3bf9afd822b8f7b896bd5095278e55d59773cd8a.zip
FreeBSD-src-3bf9afd822b8f7b896bd5095278e55d59773cd8a.tar.gz
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.
-rw-r--r--sys/sys/refcount.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/sys/sys/refcount.h b/sys/sys/refcount.h
index 9788fdf..d15dbe0 100644
--- a/sys/sys/refcount.h
+++ b/sys/sys/refcount.h
@@ -32,6 +32,15 @@
#ifndef __SYS_REFCOUNT_H__
#define __SYS_REFCOUNT_H__
+#include <machine/atomic.h>
+
+#ifdef _KERNEL
+#warning _KERNEL defined
+#include <sys/systm.h>
+#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__ */
OpenPOWER on IntegriCloud