From owner-cvs-all@FreeBSD.ORG Tue Mar 28 18:57:43 2006 Return-Path: X-Original-To: cvs-all@freebsd.org Delivered-To: cvs-all@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1CFDD16A41F; Tue, 28 Mar 2006 18:57:43 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (66-23-211-162.clients.speedfactory.net [66.23.211.162]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2D90F43D60; Tue, 28 Mar 2006 18:57:41 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from localhost (john@localhost [127.0.0.1]) by server.baldwin.cx (8.13.4/8.13.4) with ESMTP id k2SIvcYE071680; Tue, 28 Mar 2006 13:57:38 -0500 (EST) (envelope-from jhb@freebsd.org) From: John Baldwin To: "Dag-Erling =?iso-8859-1?q?Sm=F8rgrav?=" Date: Tue, 28 Mar 2006 13:58:24 -0500 User-Agent: KMail/1.9.1 References: <200603281434.k2SEYmaR031447@repoman.freebsd.org> <200603281300.09419.jhb@freebsd.org> <86psk6wilj.fsf@xps.des.no> In-Reply-To: <86psk6wilj.fsf@xps.des.no> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200603281358.26703.jhb@freebsd.org> X-Virus-Scanned: ClamAV 0.87.1/1359/Tue Mar 28 06:49:08 2006 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-3.8 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.0 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on server.baldwin.cx Cc: cvs-src@freebsd.org, src-committers@freebsd.org, cvs-all@freebsd.org Subject: Re: cvs commit: src/sys/i386/include atomic.h X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Mar 2006 18:57:43 -0000 On Tuesday 28 March 2006 13:05, Dag-Erling Sm=F8rgrav wrote: > John Baldwin writes: > > One reason for not having the casts, btw, is that you lose type > > checking. >=20 > Huh? Before my patch, any use of atomic_*_ptr with warnings turned > off would result in a slew of warnings because you'd be passing > pointers to a function which is declared to take u_int. The only way > to make this type safe is to use inline functions instead of the > macros I wrote. s/off/on/ I trust Not true. The tinderbox would attest to that. Please see code such as this: #define MTX_UNOWNED 0x00000004 /* Cookie for free mutex */ =2E.. /* Try to obtain mtx_lock once. */ #ifndef _obtain_lock #define _obtain_lock(mp, tid) \ atomic_cmpset_acq_ptr(&(mp)->mtx_lock, MTX_UNOWNED, (tid)) #endif =2E.. void _mtx_lock_sleep(struct mtx *m, uintptr_t tid, int opts, const char *file, int line) { ... uintptr_t v; ... while (!_obtain_lock(m, tid)) { ... v =3D m->mtx_lock; ... /* * If the mutex isn't already contested and a failure occurs * setting the contested bit, the mutex was either released * or the state of the MTX_RECURSED bit changed. */ if ((v & MTX_CONTESTED) =3D=3D 0 && !atomic_cmpset_ptr(&m->mtx_lock, v, v | MTX_CONTESTED)) { ... continue; } ... } ... } etc. kern_rwlock.c has this as well. The parts of the kernel that do use pointers already use explicit casts to uintptr_t where needed: dev/hatm/if_hatm_intr.c: if (atomic_cmpset_ptr((uintptr_t *)= list, (uintptr_t)buf->link, dev/hatm/if_hatm_intr.c: if (atomic_cmpset_ptr((uintptr_t *)= &sc->mbuf_list[g], dev/hatm/if_hatm_intr.c: if (atomic_cmpset_ptr((uint= ptr_t *)&sc->mbuf_list[g], Even userland uses casts when it uses void * rather than uintptr_t for the underlying type. See src/lib/libpthread/sys/lock.c or src/lib/libthr/thr_umtx.h. =2D-=20 John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" =3D http://www.FreeBSD.org