diff options
author | Jeff Hao <jeffhao@google.com> | 2013-08-15 14:51:16 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2013-08-26 14:04:16 -0700 |
commit | e9e10c13ff3fdb7104aafd0707b2c851851c9d1f (patch) | |
tree | 872463abf72b96635fdca0611679c6ace5fcee3a /libc/bionic | |
parent | 345eb225ae2e87e36354be5f1e62301179482804 (diff) | |
download | bionic-e9e10c13ff3fdb7104aafd0707b2c851851c9d1f.zip bionic-e9e10c13ff3fdb7104aafd0707b2c851851c9d1f.tar.gz bionic-e9e10c13ff3fdb7104aafd0707b2c851851c9d1f.tar.bz2 |
Fix pthread_getcpuclockid.
clock_gettime was returning EINVAL for the values
produced by pthread_getcpuclockid.
Bug: 10346183
(cherry picked from commit 9b06cc3c1b2c4e2b08582f3fc9393a05aa589766)
Change-Id: Ib81a7024c218a4502f256c3002b9030e2aaa278d
Diffstat (limited to 'libc/bionic')
-rw-r--r-- | libc/bionic/pthread_getcpuclockid.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/libc/bionic/pthread_getcpuclockid.cpp b/libc/bionic/pthread_getcpuclockid.cpp index 10046ba..d11f56a 100644 --- a/libc/bionic/pthread_getcpuclockid.cpp +++ b/libc/bionic/pthread_getcpuclockid.cpp @@ -36,7 +36,13 @@ int pthread_getcpuclockid(pthread_t t, clockid_t* clockid) { return ESRCH; } - enum { CLOCK_IDTYPE_BITS = 3 }; - *clockid = CLOCK_THREAD_CPUTIME_ID | (thread->tid << CLOCK_IDTYPE_BITS); + // The tid is stored in the top bits, but negated. + clockid_t result = ~static_cast<clockid_t>(thread->tid) << 3; + // Bits 0 and 1: clock type (0 = CPUCLOCK_PROF, 1 = CPUCLOCK_VIRT, 2 = CPUCLOCK_SCHED). + result |= 2; + // Bit 2: thread (set) or process (clear)? + result |= (1 << 2); + + *clockid = result; return 0; } |