From e9e10c13ff3fdb7104aafd0707b2c851851c9d1f Mon Sep 17 00:00:00 2001 From: Jeff Hao Date: Thu, 15 Aug 2013 14:51:16 -0700 Subject: 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 --- libc/bionic/pthread_getcpuclockid.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'libc/bionic') 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(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; } -- cgit v1.1