1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #include <unistd.h>
- #include <tls.h>
- #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 (__builtin_expect (oldval == 0, 1))
- {
- pid_t selftid = THREAD_GETMEM (THREAD_SELF, tid);
- if (__builtin_expect (selftid != 0, 1))
- return selftid;
- }
- INTERNAL_SYSCALL_DECL (err);
- pid_t result = INTERNAL_SYSCALL (getpid, err, 0);
-
- if (oldval == 0)
- THREAD_SETMEM (THREAD_SELF, tid, result);
- return result;
- }
- #endif
- extern __typeof(getpid) __getpid;
- pid_t
- __getpid (void)
- {
- #ifdef NOT_IN_libc
- INTERNAL_SYSCALL_DECL (err);
- pid_t result = INTERNAL_SYSCALL (getpid, err, 0);
- #else
- pid_t result = THREAD_GETMEM (THREAD_SELF, pid);
- if (__builtin_expect (result <= 0, 0))
- result = really_getpid (result);
- #endif
- return result;
- }
- libc_hidden_proto(getpid)
- weak_alias(__getpid, getpid)
- libc_hidden_weak(getpid)
|