From owner-cvs-all@FreeBSD.ORG Wed Mar 10 13:39:27 2004 Return-Path: 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 C102816A4CE; Wed, 10 Mar 2004 13:39:27 -0800 (PST) Received: from smtp02.syd.iprimus.net.au (smtp02.syd.iprimus.net.au [210.50.76.52]) by mx1.FreeBSD.org (Postfix) with ESMTP id 353F243D2D; Wed, 10 Mar 2004 13:39:27 -0800 (PST) (envelope-from tim@robbins.dropbear.id.au) Received: from robbins.dropbear.id.au (211.26.204.223) by smtp02.syd.iprimus.net.au (7.0.024) id 402CF870007F3FCC; Thu, 11 Mar 2004 08:39:24 +1100 Received: by robbins.dropbear.id.au (Postfix, from userid 1000) id 1BBDE41BD; Thu, 11 Mar 2004 08:40:33 +1100 (EST) Date: Thu, 11 Mar 2004 08:40:33 +1100 From: Tim Robbins To: Bruce Evans Message-ID: <20040310214033.GA98153@cat.robbins.dropbear.id.au> References: <200403090245.i292j0a6035728@repoman.freebsd.org> <20040309032248.GA88649@cat.robbins.dropbear.id.au> <20040309143223.Q234@freebsd3.cimlogic.com.au> <20040309035532.GA88825@cat.robbins.dropbear.id.au> <20040309150536.R234@freebsd3.cimlogic.com.au> <20040309043207.GA65153@kanpc.gte.com> <20040310000922.A5035@gamplex.bde.org> <20040310035912.GQ56622@elvis.mu.org> <20040310131348.GA95975@cat.robbins.dropbear.id.au> <20040311044539.S2105@gamplex.bde.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040311044539.S2105@gamplex.bde.org> User-Agent: Mutt/1.4.1i cc: src-committers@freebsd.org cc: cvs-src@freebsd.org cc: Alfred Perlstein cc: cvs-all@freebsd.org cc: John Birrell cc: Alexander Kabaev cc: John Birrell Subject: Re: cvs commit: src/lib/libc/stdio _flock_stub.c local.h X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.1 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: Wed, 10 Mar 2004 21:39:27 -0000 On Thu, Mar 11, 2004 at 05:19:07AM +1100, Bruce Evans wrote: > On Thu, 11 Mar 2004, Tim Robbins wrote: > > > On Tue, Mar 09, 2004 at 07:59:12PM -0800, Alfred Perlstein wrote: > > > ... > > > #define getc() (__isthreaded ? old_unlocked_code : getc_unlocked()) > > ... > > If there aren't any objections, I think we should implement getc()/putc() > > this way (and all the other stdio functions that have traditionally had > > macro equivalents) before 5-stable to try to recoup some of the performance > > losses caused by the removal of the macros. > > Is __isthreaded always set early enough? What about if the application is > dynamically linked and loads thread support later (is this supported)? __isthreaded is zero initially, and set to something non-zero when the first thread is created. The initial zero value is safe to use in getc() in the main thread of applications linked to thread libraries since, barring misuse of signal handlers or funopen(), another thread cannot be created until getc() returns. We also have to assume that __isthreaded will never go from being non-zero to zero. Both of these assumptions seem to have already been made implicitly by the way FLOCKFILE() and FUNLOCKFILE() are implemented. > > The 5% cost of checking on every call can be avoided by pushing the check > into a fucntion. E.g.: for getc(): > > % #define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) > > It can be arranged that --(p)->_r < 0 is always true for the threaded case > (by keeping only a flag in it and keeping the real count elsewhere). ... This seems to require a fair bit more effort than using __isthreaded, so I'll think about this once I've implemented that approach. Tim