From: Florian Weimer <fweimer@redhat.com>
To: lihuiba <magazine.lihuiba@163.com>, libc-help@sourceware.org
Subject: Re: a question about the implementation of errno
Date: Wed, 04 Jul 2018 10:35:00 -0000 [thread overview]
Message-ID: <5f0618ef-6663-3358-a973-a358e5fe3995@redhat.com> (raw)
In-Reply-To: <19bfad75.513b.16463b06140.Coremail.magazine.lihuiba@163.com>
On 07/04/2018 07:07 AM, lihuiba wrote:
> I noticed recently that errno is implemented as a macro that expands to (*__errno_location()).
> I wonder why it is implemented as this, and why it is not a thread-local int variable.
> I suppose thread-local int is faster than function all.
Thread-local errno was added when the library (and the dynamic linker)
did not support proper TLS variables.
We haven't changed it because it is not clear that it is a win. On some
platforms, the instruction sequence to call __errno_location and then
load the value from the returned pointer is actually *shorter* than a
TLS variable access. Since access to errno happens mostly on error
paths (where performance isn't a concern, in general), we expect that
the shorter instruction sequence preferable here.
Thanks,
Florian
next prev parent reply other threads:[~2018-07-04 10:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-04 5:07 lihuiba
2018-07-04 10:35 ` Florian Weimer [this message]
2018-07-04 11:34 ` lihuiba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5f0618ef-6663-3358-a973-a358e5fe3995@redhat.com \
--to=fweimer@redhat.com \
--cc=libc-help@sourceware.org \
--cc=magazine.lihuiba@163.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).