[v2,2/8] linux: Use __libc_single_threaded on fork

Message ID 20210311195210.3153729-2-adhemerval.zanella@linaro.org
State Committed
Commit 2883de072093ecdb3369cdcd72d69d4fc7b5ae71
Delegated to: Adhemerval Zanella Netto
Headers
Series [v2,1/8] posix: Consolidate register-atfork |

Commit Message

Adhemerval Zanella Netto March 11, 2021, 7:52 p.m. UTC
  Changes from v1:
* Fix __libc_single_threaded backwards usage.
---
Checked on x86_64-linux-gnu.
---
 sysdeps/nptl/fork.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Florian Weimer March 11, 2021, 8:18 p.m. UTC | #1
* Adhemerval Zanella via Libc-alpha:

> Changes from v1:
> * Fix __libc_single_threaded backwards usage.
> ---
> Checked on x86_64-linux-gnu.
> ---
>  sysdeps/nptl/fork.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/sysdeps/nptl/fork.c b/sysdeps/nptl/fork.c
> index 4fb4c2d254..f78267b68c 100644
> --- a/sysdeps/nptl/fork.c
> +++ b/sysdeps/nptl/fork.c
> @@ -34,6 +34,7 @@
>  #include <malloc/malloc-internal.h>
>  #include <nss/nss_database.h>
>  #include <unwind-link.h>
> +#include <sys/single_threaded.h>
>  
>  static void
>  fresetlockfiles (void)
> @@ -55,7 +56,7 @@ __libc_fork (void)
>       handlers in the single-thread case, to make fork safer to use in
>       signal handlers.  POSIX requires that fork is async-signal-safe,
>       but our current fork implementation is not.  */
> -  bool multiple_threads = THREAD_GETMEM (THREAD_SELF, header.multiple_threads);
> +  bool multiple_threads = __libc_single_threaded == 0;
>  
>    __run_fork_handlers (atfork_run_prepare, multiple_threads);

Okay, this code isn't performance-sensitive, given that fork itself is
so expensive, so it doesn't matter which single-thread check is used.

Thanks,
Florian
  

Patch

diff --git a/sysdeps/nptl/fork.c b/sysdeps/nptl/fork.c
index 4fb4c2d254..f78267b68c 100644
--- a/sysdeps/nptl/fork.c
+++ b/sysdeps/nptl/fork.c
@@ -34,6 +34,7 @@ 
 #include <malloc/malloc-internal.h>
 #include <nss/nss_database.h>
 #include <unwind-link.h>
+#include <sys/single_threaded.h>
 
 static void
 fresetlockfiles (void)
@@ -55,7 +56,7 @@  __libc_fork (void)
      handlers in the single-thread case, to make fork safer to use in
      signal handlers.  POSIX requires that fork is async-signal-safe,
      but our current fork implementation is not.  */
-  bool multiple_threads = THREAD_GETMEM (THREAD_SELF, header.multiple_threads);
+  bool multiple_threads = __libc_single_threaded == 0;
 
   __run_fork_handlers (atfork_run_prepare, multiple_threads);