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.
This commit is contained in:
Dag-Erling Smørgrav 2008-07-23 16:40:07 +00:00
parent c3c6456251
commit 75f31a5fe4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=180762

View File

@ -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__ */