From owner-cvs-src@FreeBSD.ORG  Mon Mar 12 20:42:15 2007
Return-Path: <owner-cvs-src@FreeBSD.ORG>
X-Original-To: cvs-src@freebsd.org
Delivered-To: cvs-src@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 84E6D16A401;
	Mon, 12 Mar 2007 20:42:15 +0000 (UTC)
	(envelope-from pjd@garage.freebsd.pl)
Received: from mail.garage.freebsd.pl (arm132.internetdsl.tpnet.pl
	[83.17.198.132])
	by mx1.freebsd.org (Postfix) with ESMTP id B98A013C457;
	Mon, 12 Mar 2007 20:42:14 +0000 (UTC)
	(envelope-from pjd@garage.freebsd.pl)
Received: by mail.garage.freebsd.pl (Postfix, from userid 65534)
	id C030345CD9; Mon, 12 Mar 2007 21:42:12 +0100 (CET)
Received: from localhost (154.81.datacomsa.pl [195.34.81.154])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mail.garage.freebsd.pl (Postfix) with ESMTP id B214945684;
	Mon, 12 Mar 2007 21:42:06 +0100 (CET)
Date: Mon, 12 Mar 2007 21:42:05 +0100
From: Pawel Jakub Dawidek <pjd@FreeBSD.org>
To: John Baldwin <jhb@freebsd.org>
Message-ID: <20070312204205.GC5688@garage.freebsd.pl>
References: <200703092241.l29Mf2Ds062856@repoman.freebsd.org>
	<200703121535.22140.jhb@freebsd.org>
	<20070312200345.GB5688@garage.freebsd.pl>
	<200703121618.41084.jhb@freebsd.org>
MIME-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="TiqCXmo5T1hvSQQg"
Content-Disposition: inline
In-Reply-To: <200703121618.41084.jhb@freebsd.org>
X-PGP-Key-URL: http://people.freebsd.org/~pjd/pjd.asc
X-OS: FreeBSD 7.0-CURRENT i386
User-Agent: mutt-ng/devel-r804 (FreeBSD)
X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on 
	mail.garage.freebsd.pl
X-Spam-Level: 
X-Spam-Status: No, score=-2.6 required=3.0 tests=BAYES_00 autolearn=ham 
	version=3.0.4
Cc: Attilio Rao <attilio@freebsd.org>, cvs-src@freebsd.org,
	src-committers@freebsd.org, cvs-all@freebsd.org
Subject: Re: cvs commit: src/share/man/man9 Makefile condvar.9 lock.9
	mi_switch.9 mtx_pool.9 mutex.9 rwlock.9 sleep.9 sleepqueue.9
	sx.9 thread_exit.9 src/sys/kern kern_synch.c src/sys/sys
	mutex.h rwlock.h sleepqueue.h sx.h systm.h
X-BeenThere: cvs-src@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: CVS commit messages for the src tree <cvs-src.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/cvs-src>,
	<mailto:cvs-src-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/cvs-src>
List-Post: <mailto:cvs-src@freebsd.org>
List-Help: <mailto:cvs-src-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/cvs-src>,
	<mailto:cvs-src-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Mon, 12 Mar 2007 20:42:15 -0000


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

On Mon, Mar 12, 2007 at 04:18:40PM -0400, John Baldwin wrote:
> On Monday 12 March 2007 16:03, Pawel Jakub Dawidek wrote:
> > On Mon, Mar 12, 2007 at 03:35:21PM -0400, John Baldwin wrote:
> > > On Monday 12 March 2007 14:56, Pawel Jakub Dawidek wrote:
> > > > On Mon, Mar 12, 2007 at 11:16:23AM -0400, John Baldwin wrote:
> > > > > On Saturday 10 March 2007 15:52, Pawel Jakub Dawidek wrote:
> > > > > > What about something like this:
> > > > > >=20
> > > > > > #define	cv_wait(cv, lock)	do {
> > > > > > 	switch (LO_CLASSINDEX((struct lock_object *)(lock))) {
> > > > >=20
> > > > > The problem with a cast is you use type checking.  Might as well =
do=20
> this:
> > > > >=20
> > > > > #define	cv_wait(cv, lock)	_cv_wait((cv), (struct lock_object *)(l=
ock))
> > > >=20
> > > > This will skip type checking and my version only cast to provide ty=
pe
> > > > checking, so when you pass some random variable it will give you an
> > > > error.
> > >=20
> > > Not really, you may pass some garbage and the LO_CLASSINDEX turns out=
 to=20
> be a=20
> > > mutex. :)  You only get a runtime error, not a compile-time one. =20
> > > Type-checking by the compiler is nice because you get compile-time er=
rors.
> >=20
> > I'll get compile-time error, because cv_wait_mtx() takes
> > 'struct condvar *' and 'struct mtx *' as arguments. So even if some
> > garbage returns 1, which turns out to be a mutex, call to cv_wait_mtx()
> > will generate compile-time error.
>=20
> Err, no, actually, yours will always give compile errors actually.  Keep =
in=20
> mind that LO_CLASSINDEX() is a run-time check.  This:
>=20
> #define cv_wait(cv, lock)       do {
>         switch (LO_CLASSINDEX((struct lock_object *)(lock))) {
>         case 1:
>                 cv_wait_mtx(cv, lock);
>                 break;
>         case 2:
>                 cv_wait_sx(cv, lock);
>                 break;
>         case 3:
>                 cv_wait_rw(cv, lock);
>                 break;
>         default:
>                 panic("Invalid lock.");
>         }
> } while (0)
>=20
> Will try to pass 'lock' to three different functions, at least 2 of which=
 will=20
> trigger compile errors. :)  The kernel won't choose which one to run unti=
l=20
> runtime though.  The key is that I want a compile error, not a panic(). :)

Ah, you are right.

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

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

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

iD8DBQFF9bsdForvXbEpPzQRAuxLAJ42gy497h9MvbR3eLU+8Z43M4+PpACgzNxW
kFYB7jdQEOllvlT7XJABU0M=
=dc/E
-----END PGP SIGNATURE-----

--TiqCXmo5T1hvSQQg--