From owner-cvs-src@FreeBSD.ORG Mon Mar 12 23:45:19 2007 Return-Path: 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 BBAF716A407 for ; Mon, 12 Mar 2007 23:45:19 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outC.internet-mail-service.net (outC.internet-mail-service.net [216.240.47.226]) by mx1.freebsd.org (Postfix) with ESMTP id 929DC13C45D for ; Mon, 12 Mar 2007 23:45:19 +0000 (UTC) (envelope-from julian@elischer.org) Received: from mx0.idiom.com (HELO idiom.com) (216.240.32.160) by out.internet-mail-service.net (qpsmtpd/0.32) with ESMTP; Mon, 12 Mar 2007 16:07:22 -0700 Received: from [10.251.22.38] (nat.ironport.com [63.251.108.100]) by idiom.com (Postfix) with ESMTP id 91322125CE5; Mon, 12 Mar 2007 16:28:00 -0700 (PDT) Message-ID: <45F5E1F9.5090806@elischer.org> Date: Mon, 12 Mar 2007 16:27:53 -0700 From: Julian Elischer User-Agent: Thunderbird 1.5.0.10 (Macintosh/20070221) MIME-Version: 1.0 To: John Baldwin References: <200703092241.l29Mf2Ds062856@repoman.freebsd.org> <200703121535.22140.jhb@freebsd.org> <20070312200345.GB5688@garage.freebsd.pl> <200703121618.41084.jhb@freebsd.org> In-Reply-To: <200703121618.41084.jhb@freebsd.org> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Cc: Attilio Rao , cvs-src@freebsd.org, src-committers@freebsd.org, Pawel Jakub Dawidek , 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Mar 2007 23:45:19 -0000 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: >>>>>> >>>>>> #define cv_wait(cv, lock) do { >>>>>> switch (LO_CLASSINDEX((struct lock_object *)(lock))) { >>>>> The problem with a cast is you use type checking. Might as well do > this: >>>>> #define cv_wait(cv, lock) _cv_wait((cv), (struct lock_object *)(lock)) >>>> This will skip type checking and my version only cast to provide type >>>> checking, so when you pass some random variable it will give you an >>>> error. >>> Not really, you may pass some garbage and the LO_CLASSINDEX turns out to > be a >>> mutex. :) You only get a runtime error, not a compile-time one. >>> Type-checking by the compiler is nice because you get compile-time errors. >> 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. > > Err, no, actually, yours will always give compile errors actually. Keep in > mind that LO_CLASSINDEX() is a run-time check. This: > > #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) > > Will try to pass 'lock' to three different functions, at least 2 of which will > trigger compile errors. :) The kernel won't choose which one to run until > runtime though. The key is that I want a compile error, not a panic(). :) I've been asking for awhile that for example spin and sleep mutexes should be different types so that we could catch those problems at compile time. >