am 6b6aaec8: am 4eacb341: Merge "Fix pthread_getcpuclockid."

* commit '6b6aaec892b1f256787fbbf106449f7d7e5888a2':
  Fix pthread_getcpuclockid.
This commit is contained in:
Elliott Hughes 2013-08-16 12:25:58 -07:00 committed by Android Git Automerger
commit e714eb157e
3 changed files with 19 additions and 3 deletions

View File

@ -36,7 +36,13 @@ int pthread_getcpuclockid(pthread_t t, clockid_t* clockid) {
return ESRCH; return ESRCH;
} }
enum { CLOCK_IDTYPE_BITS = 3 }; // The tid is stored in the top bits, but negated.
*clockid = CLOCK_THREAD_CPUTIME_ID | (thread->tid << CLOCK_IDTYPE_BITS); 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; return 0;
} }

View File

@ -157,7 +157,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE := bionic-unit-tests-glibc LOCAL_MODULE := bionic-unit-tests-glibc
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
LOCAL_CFLAGS += $(test_c_flags) LOCAL_CFLAGS += $(test_c_flags)
LOCAL_LDFLAGS += -lpthread -ldl LOCAL_LDFLAGS += -lpthread -ldl -lrt
LOCAL_LDFLAGS += $(test_dynamic_ldflags) LOCAL_LDFLAGS += $(test_dynamic_ldflags)
LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files) LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files)
LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl-host LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl-host

View File

@ -278,6 +278,16 @@ TEST(pthread, pthread_detach__no_such_thread) {
ASSERT_EQ(ESRCH, pthread_detach(dead_thread)); ASSERT_EQ(ESRCH, pthread_detach(dead_thread));
} }
TEST(pthread, pthread_getcpuclockid__clock_gettime) {
pthread_t t;
ASSERT_EQ(0, pthread_create(&t, NULL, SleepFn, reinterpret_cast<void*>(5)));
clockid_t c;
ASSERT_EQ(0, pthread_getcpuclockid(t, &c));
timespec ts;
ASSERT_EQ(0, clock_gettime(c, &ts));
}
TEST(pthread, pthread_getcpuclockid__no_such_thread) { TEST(pthread, pthread_getcpuclockid__no_such_thread) {
pthread_t dead_thread; pthread_t dead_thread;
MakeDeadThread(dead_thread); MakeDeadThread(dead_thread);