[PATCH v2] Single threaded stdio optimization
Szabolcs Nagy
szabolcs.nagy@arm.com
Thu Jun 29 13:29:00 GMT 2017
On 29/06/17 12:41, Siddhesh Poyarekar wrote:
>> @@ -32,6 +32,8 @@ _IO_ferror (_IO_FILE *fp)
>> {
>> int result;
>> CHECK_FILE (fp, EOF);
>> + if (!_IO_need_lock (fp))
>> + return _IO_ferror_unlocked (fp);
>> _IO_flockfile (fp);
>> result = _IO_ferror_unlocked (fp);
>
> The patch looks OK except for the duplication (and a missing comment
> below), which looks a bit clumsy. How about something like this instead:
>
> bool need_lock = _IO_need_lock (fp);
>
> if (need_lock)
> _IO_flockfile (fp);
> result = _IO_ferror_unlocked (fp);
> if (need_lock)
> _IO_funlockfile (fp);
>
> return result;
>
> You could probably make some kind of a macro out of this, I haven't
> looked that hard.
>
this does not do what we want:
single check + tailcall the unlocked version.
with your code gcc is more likely to do two
checks and register spills and an additional
return.
while my code does not force gcc to do the
right thing at least it shows the intent.
More information about the Libc-alpha
mailing list