cvs commit: src/lib/libc/stdio _flock_stub.c local.h

Tim Robbins tjr at freebsd.org
Wed Mar 10 13:39:27 PST 2004


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


More information about the cvs-all mailing list