about summary refs log tree commit diff
path: root/nptl/sysdeps/unix/sysv/linux/getpid.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-12-20 23:39:42 +0000
committerUlrich Drepper <drepper@redhat.com>2003-12-20 23:39:42 +0000
commitc0ecb80a43103964d30d8629ce45098fca307081 (patch)
tree859db25ae2d571c91dabf49a70c8c2e1da535ebe /nptl/sysdeps/unix/sysv/linux/getpid.c
parentbbe35eb57144c081d10e76e35e52e9b400202b72 (diff)
downloadglibc-c0ecb80a43103964d30d8629ce45098fca307081.tar.gz
glibc-c0ecb80a43103964d30d8629ce45098fca307081.tar.xz
glibc-c0ecb80a43103964d30d8629ce45098fca307081.zip
Update.
2003-12-20  Ulrich Drepper  <drepper@redhat.com>

	* elf/rtld.c (dl_main): Optimize order or subexpressions in if().
Diffstat (limited to 'nptl/sysdeps/unix/sysv/linux/getpid.c')
-rw-r--r--nptl/sysdeps/unix/sysv/linux/getpid.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/nptl/sysdeps/unix/sysv/linux/getpid.c b/nptl/sysdeps/unix/sysv/linux/getpid.c
index 75decc1385..7efe3f2768 100644
--- a/nptl/sysdeps/unix/sysv/linux/getpid.c
+++ b/nptl/sysdeps/unix/sysv/linux/getpid.c
@@ -22,21 +22,31 @@
 #include <sysdep.h>
 
 
+#ifndef NOT_IN_libc
+static pid_t really_getpid (pid_t oldval);
+#endif
+
+
 pid_t
 __getpid (void)
 {
-  pid_t result;
 #ifndef NOT_IN_libc
-  result = THREAD_GETMEM (THREAD_SELF, pid);
-  if (__builtin_expect (result == 0, 0))
+  pid_t result = THREAD_GETMEM (THREAD_SELF, pid);
+  if (__builtin_expect (result <= 0, 0))
+    result = really_getpid (result);
+  return result;
+}
+
+static pid_t
+really_getpid (pid_t oldval)
+{
 #endif
-    {
-      INTERNAL_SYSCALL_DECL (err);
-      result = INTERNAL_SYSCALL (getpid, err, 0);
+  INTERNAL_SYSCALL_DECL (err);
+  pid_t result = INTERNAL_SYSCALL (getpid, err, 0);
 #ifndef NOT_IN_libc
-      THREAD_SETMEM (THREAD_SELF, pid, result);
+  if (oldval == 0)
+    THREAD_SETMEM (THREAD_SELF, pid, result);
 #endif
-    }
   return result;
 }
 libc_hidden_def (__getpid)