]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Simplify getpid handling of the race case. roland/getpid
authorRoland McGrath <roland@hack.frob.com>
Fri, 9 May 2014 21:18:59 +0000 (14:18 -0700)
committerRoland McGrath <roland@hack.frob.com>
Fri, 9 May 2014 21:18:59 +0000 (14:18 -0700)
ChangeLog
nptl/sysdeps/unix/sysv/linux/getpid.c

index 2c08c5041ce465d0718da444be4abc820dfa8738..0f0238d81b76730dfc230b604a61a04251d6d224 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2014-05-09  Roland McGrath  <roland@hack.frob.com>
+
+       * nptl/sysdeps/unix/sysv/linux/getpid.c
+       (really_getpid): Function removed.
+       (__getpid): Rewritten.  Under [!NOT_IN_libc], use THREAD_SELF->pid if
+       it's > 0.  Otherwise always just make the system call.
+
 2014-05-09  Roland McGrath  <roland@hack.frob.com>
 
        * sysdeps/arm/armv7/strcmp.S: Use sfi_breg prefix on loads not from sp.
index 937b1d4e113b1cff4a5c698f83d662e130d596af..9dcf38cc303a7d5f64d8e93f2d75e161249a5d0f 100644 (file)
 #include <sysdep.h>
 
 
-#ifndef NOT_IN_libc
-static inline __attribute__((always_inline)) pid_t really_getpid (pid_t oldval);
-
-static inline __attribute__((always_inline)) pid_t
-really_getpid (pid_t oldval)
-{
-  if (__glibc_likely (oldval == 0))
-    {
-      pid_t selftid = THREAD_GETMEM (THREAD_SELF, tid);
-      if (__glibc_likely (selftid != 0))
-       return selftid;
-    }
-
-  INTERNAL_SYSCALL_DECL (err);
-  pid_t result = INTERNAL_SYSCALL (getpid, err, 0);
-
-  /* We do not set the PID field in the TID here since we might be
-     called from a signal handler while the thread executes fork.  */
-  if (oldval == 0)
-    THREAD_SETMEM (THREAD_SELF, tid, result);
-  return result;
-}
-#endif
-
 pid_t
 __getpid (void)
 {
-#ifdef NOT_IN_libc
-  INTERNAL_SYSCALL_DECL (err);
-  pid_t result = INTERNAL_SYSCALL (getpid, err, 0);
-#else
+#ifndef NOT_IN_libc
   pid_t result = THREAD_GETMEM (THREAD_SELF, pid);
-  if (__glibc_unlikely (result <= 0))
-    result = really_getpid (result);
+  if (__glibc_likely (result > 0))
+    return result;
 #endif
-  return result;
+
+  INTERNAL_SYSCALL_DECL (err);
+  return INTERNAL_SYSCALL (getpid, err, 0);
 }
 
 libc_hidden_def (__getpid)