Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Jun 2004 20:37:03 +0200
From:      Pawel Jakub Dawidek <pjd@FreeBSD.org>
To:        Julian Elischer <julian@elischer.org>
Cc:        Poul-Henning Kamp <phk@phk.freebsd.dk>
Subject:   Re: cvs commit: src/sys/kern kern_proc.c
Message-ID:  <20040609183703.GX12007@darkness.comp.waw.pl>
In-Reply-To: <Pine.BSF.4.21.0406091109100.57882-100000@InterJet.elischer.org>
References:  <57019.1086804305@critter.freebsd.dk> <Pine.BSF.4.21.0406091109100.57882-100000@InterJet.elischer.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--KZCIPwrNpw38UenM
Content-Type: text/plain; charset=iso-8859-2
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Jun 09, 2004 at 11:23:48AM -0700, Julian Elischer wrote:
+> I do actually agree that a general purpose reference counting=20
+> API is very difficult to use in every situation and that there=20
+> are situations where you just HAVE to roll your own..

Maybe we can use macros to do this, something like:

#define	REFCNT_MTX(foo, prefix, type, mtx_field, refcnt_field, destroy_func=
) \
foo void								\
prefix ## _hold(type *obj)						\
{									\
									\
	mtx_lock(&obj->mtx_field);					\
	obj->refcnt_field++;						\
	mtx_unlock(&obj->mtx_field);					\
}									\
									\
foo void								\
prefix ## _free(type *obj)						\
{									\
	int refcnt;							\
									\
	mtx_lock(&obj->mtx_field);					\
	refcnt =3D --obj->refcnt_field;					\
	mtx_unlock(&obj->mtx_field);					\
	if (refcnt =3D=3D 0)						\
		destroy_func(obj);					\
}

And the same for REFCNT_ATOMIC() and REFCNT_SPIN()?
'foo' could be for example 'static' or 'static __inline'.

--=20
Pawel Jakub Dawidek                       http://www.FreeBSD.org
pjd@FreeBSD.org                           http://garage.freebsd.pl
FreeBSD committer                         Am I Evil? Yes, I Am!

--KZCIPwrNpw38UenM
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFAx1jPForvXbEpPzQRAq2JAJ47cECI0Tkw1cnV2Ve2XhDn+TN0YQCeJ5aQ
Vvxce9IR1yBIH5qvHGtFTsU=
=g99S
-----END PGP SIGNATURE-----

--KZCIPwrNpw38UenM--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040609183703.GX12007>