summaryrefslogtreecommitdiff
path: root/nptl/sysdeps/unix/sysv/linux/getpid.c
diff options
context:
space:
mode:
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)