summaryrefslogtreecommitdiffstats
path: root/libc
diff options
context:
space:
mode:
authorJeff Hao <jeffhao@google.com>2013-08-15 14:51:16 -0700
committerElliott Hughes <enh@google.com>2013-08-15 15:34:22 -0700
commit9b06cc3c1b2c4e2b08582f3fc9393a05aa589766 (patch)
tree230f8e9cadd5dbd6a854b9e7c63f9707a4f84400 /libc
parentcf0529946a0ffd07e94785102965656768e455e1 (diff)
downloadbionic-9b06cc3c1b2c4e2b08582f3fc9393a05aa589766.zip
bionic-9b06cc3c1b2c4e2b08582f3fc9393a05aa589766.tar.gz
bionic-9b06cc3c1b2c4e2b08582f3fc9393a05aa589766.tar.bz2
Fix pthread_getcpuclockid.
clock_gettime was returning EINVAL for the values produced by pthread_getcpuclockid. Bug: 10346183 Change-Id: Iabe643d7d46110bb311a0367aa0fc737f653208e
Diffstat (limited to 'libc')
-rw-r--r--libc/bionic/pthread_getcpuclockid.cpp10
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;
}