Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Mar 2004 08:40:33 +1100
From:      Tim Robbins <tjr@freebsd.org>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        John Birrell <jb@cimlogic.com.au>
Subject:   Re: cvs commit: src/lib/libc/stdio _flock_stub.c local.h
Message-ID:  <20040310214033.GA98153@cat.robbins.dropbear.id.au>
In-Reply-To: <20040311044539.S2105@gamplex.bde.org>
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>

next in thread | previous in thread | raw e-mail | index | archive | help
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



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