]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hurd: Microoptimize _hurd_self_sigstate ()
authorSergey Bugaev <bugaevc@gmail.com>
Sun, 19 Mar 2023 15:10:14 +0000 (18:10 +0300)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 2 Apr 2023 23:25:57 +0000 (01:25 +0200)
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>

hurd/hurd/signal.h

index c33f974b1bac1dc77909d93d9c1f667e8f97c1cd..662e955e9495af2f9b8a2fe5e84b1fd5f8b3548f 100644 (file)
@@ -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