Simplify getpid handling of the race case.
[glibc.git] / nptl / sysdeps / unix / sysv / linux / getpid.c
blob9dcf38cc303a7d5f64d8e93f2d75e161249a5d0f
1 /* Copyright (C) 2003-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <unistd.h>
20 #include <tls.h>
21 #include <sysdep.h>
24 pid_t
25 __getpid (void)
27 #ifndef NOT_IN_libc
28 pid_t result = THREAD_GETMEM (THREAD_SELF, pid);
29 if (__glibc_likely (result > 0))
30 return result;
31 #endif
33 INTERNAL_SYSCALL_DECL (err);
34 return INTERNAL_SYSCALL (getpid, err, 0);
37 libc_hidden_def (__getpid)
38 weak_alias (__getpid, getpid)
39 libc_hidden_def (getpid)