Cache getpid.
authorElliott Hughes <enh@google.com>
Thu, 19 Jun 2014 23:39:01 +0000 (16:39 -0700)
committerElliott Hughes <enh@google.com>
Fri, 20 Jun 2014 16:06:57 +0000 (09:06 -0700)
commit7086ad6919feb2415c6027163f5c63323bcca27c
treef32c06d513e90ba1fcb8fe56f9cd055cccc7d01b
parentd1bf37780d0bcaca3e6046171f958ebfea34bde1
Cache getpid.

In practice, with this implementation we never need to make a system call.
We get the main thread's tid (which is the same as our pid) back from
the set_tid_address system call we have to make during initialization.
A new pthread will have the same pid as its parent, and a fork child's
main (and only) thread will have a pid equal to its tid, which we get for
free from the kernel before clone returns.

The only time we'd actually have to make a getpid system call now is if
we take a signal during fork and the signal handler calls getpid. (That,
or we call getpid in the dynamic linker while it's still dealing with its
own relocations and hasn't even set up the main thread yet.)

Bug: 15387103
Change-Id: I6d4718ed0a5c912fc75b5f738c49a023dbed5189
15 files changed:
benchmarks/unistd_benchmark.cpp
libc/Android.mk
libc/SYSCALLS.TXT
libc/arch-arm/syscalls/__getpid.S [moved from libc/arch-arm/syscalls/getpid.S with 89% similarity]
libc/arch-arm64/syscalls/__getpid.S [moved from libc/arch-arm64/syscalls/getpid.S with 82% similarity]
libc/arch-mips/syscalls/__getpid.S [moved from libc/arch-mips/syscalls/getpid.S with 89% similarity]
libc/arch-mips64/syscalls/__getpid.S [moved from libc/arch-mips64/syscalls/getpid.S with 87% similarity]
libc/arch-x86/syscalls/__getpid.S [moved from libc/arch-x86/syscalls/getpid.S with 89% similarity]
libc/arch-x86_64/syscalls/__getpid.S [moved from libc/arch-x86_64/syscalls/getpid.S with 83% similarity]
libc/bionic/fork.cpp
libc/bionic/getpid.cpp [new file with mode: 0644]
libc/bionic/libc_init_common.cpp
libc/bionic/pthread_create.cpp
libc/bionic/pthread_internal.h
tests/unistd_test.cpp