public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Samuel Thibault <sthibaul@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc] hurd: Microoptimize _hurd_self_sigstate ()
Date: Sun,  2 Apr 2023 23:29:10 +0000 (GMT)	[thread overview]
Message-ID: <20230402232910.D0252385840F@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=7b3d8558d92a123743699c577704aab4a2f3d949

commit 7b3d8558d92a123743699c577704aab4a2f3d949
Author: Sergey Bugaev <bugaevc@gmail.com>
Date:   Sun Mar 19 18:10:14 2023 +0300

    hurd: Microoptimize _hurd_self_sigstate ()
    
    When THREAD_GETMEM is defined with inline assembly, the compiler may not
    optimize away the two reads of _hurd_sigstate. Help it out a little bit
    by only reading it once. This also makes for a slightly cleaner code.
    
    Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
    Message-Id: <20230319151017.531737-32-bugaevc@gmail.com>

Diff:
---
 hurd/hurd/signal.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/hurd/hurd/signal.h b/hurd/hurd/signal.h
index c33f974b1b..662e955e94 100644
--- a/hurd/hurd/signal.h
+++ b/hurd/hurd/signal.h
@@ -166,13 +166,15 @@ extern void _hurd_sigstate_delete (thread_t thread);
 _HURD_SIGNAL_H_EXTERN_INLINE struct hurd_sigstate *
 _hurd_self_sigstate (void)
 {
-  if (THREAD_GETMEM (THREAD_SELF, _hurd_sigstate) == NULL)
+  struct hurd_sigstate *ss = THREAD_GETMEM (THREAD_SELF, _hurd_sigstate);
+  if (__glibc_unlikely (ss == NULL))
     {
       thread_t self = __mach_thread_self ();
-      THREAD_SETMEM (THREAD_SELF, _hurd_sigstate, _hurd_thread_sigstate (self));
+      ss = _hurd_thread_sigstate (self);
+      THREAD_SETMEM (THREAD_SELF, _hurd_sigstate, ss);
       __mach_port_deallocate (__mach_task_self (), self);
     }
-  return THREAD_GETMEM (THREAD_SELF, _hurd_sigstate);
+  return ss;
 }
 # endif
 #endif

                 reply	other threads:[~2023-04-02 23:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230402232910.D0252385840F@sourceware.org \
    --to=sthibaul@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /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).