From dbaf5693972d2cbfad0ad48b966e5693b770127e Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sun, 22 Apr 2012 00:22:47 +0200 Subject: __pthread_timedblock: add an argument for the clock id To make `__pthread_timedblock' properly measure time using the right clock, add a new argument representing the clock to use. * pthread/pt-internal.h (__pthread_timedblock): New argument CLOCK_ID. * sysdeps/l4/pt-timedblock.c (__pthread_timedblock): Likewise. * sysdeps/mach/pt-timedblock.c (__pthread_timedblock): Likewise. * sysdeps/generic/pt-cond-timedwait.c (__pthread_cond_timedwait_internal): Pass the clock of the `pthread_cond' to `__pthread_timedblock'. * sysdeps/generic/pt-mutex-timedlock.c (__pthread_mutex_timedlock_internal): Pass CLOCK_REALTIME to `__pthread_timedblock'. * sysdeps/generic/pt-rwlock-timedrdlock.c (__pthread_rwlock_timedrdlock_internal): Likewise. * sysdeps/generic/pt-rwlock-timedwrlock.c (__pthread_rwlock_timedwrlock_internal): Likewise. * sysdeps/generic/sem-timedwait.c (__sem_timedwait_internal): Likewise. --- sysdeps/mach/pt-timedblock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sysdeps/mach/pt-timedblock.c') diff --git a/sysdeps/mach/pt-timedblock.c b/sysdeps/mach/pt-timedblock.c index 6f54726..88beaa2 100644 --- a/sysdeps/mach/pt-timedblock.c +++ b/sysdeps/mach/pt-timedblock.c @@ -30,7 +30,8 @@ /* Block THREAD. */ error_t __pthread_timedblock (struct __pthread *thread, - const struct timespec *abstime) + const struct timespec *abstime, + clockid_t clock_id) { error_t err; mach_msg_header_t msg; -- cgit v1.2.3 From 69e89a859882e4f675dd5491edc969159d8a4002 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sun, 22 Apr 2012 00:38:26 +0200 Subject: __pthread_timedblock: switch to clock_gettime Use `clock_gettime' with the provided clock instead of `gettimeofday', linking to rt. * sysdeps/mach/pt-timedblock.c (__pthread_timedblock): Switch to `clock_gettime'. * Makefile [!IN_GLIBC] (LDLIBS): Link to rt. [IN_GLIBC] ($(objpfx)libpthread.so): Likewise. * Makefile.am (libpthread_a_LDADD): Likewise. --- Makefile | 2 ++ Makefile.am | 2 ++ sysdeps/mach/pt-timedblock.c | 13 ++++++------- 3 files changed, 10 insertions(+), 7 deletions(-) (limited to 'sysdeps/mach/pt-timedblock.c') diff --git a/Makefile b/Makefile index b291177..bee4e3c 100644 --- a/Makefile +++ b/Makefile @@ -210,8 +210,10 @@ VPATH += $(SYSDEP_PATH) ifeq ($(IN_GLIBC),no) HURDLIBS = ihash +LDLIBS = -lrt else LDLIBS-pthread.so = -lihash +$(objpfx)libpthread.so: $(common-objpfx)rt/librt.so endif ifeq ($(IN_GLIBC),no) diff --git a/Makefile.am b/Makefile.am index e1c062c..36ede54 100644 --- a/Makefile.am +++ b/Makefile.am @@ -166,3 +166,5 @@ libpthread_a_SOURCES = pt-attr.c pt-attr-destroy.c pt-attr-getdetachstate.c \ sigwaitinfo.c \ signal-dispatch-lowlevel.c \ sigprocmask.c + +libpthread_a_LDADD = -lrt diff --git a/sysdeps/mach/pt-timedblock.c b/sysdeps/mach/pt-timedblock.c index 88beaa2..d72ef73 100644 --- a/sysdeps/mach/pt-timedblock.c +++ b/sysdeps/mach/pt-timedblock.c @@ -36,27 +36,26 @@ __pthread_timedblock (struct __pthread *thread, error_t err; mach_msg_header_t msg; mach_msg_timeout_t timeout; - struct timeval now; + struct timespec now; /* We have an absolute time and now we have to convert it to a relative time. Arg. */ - err = gettimeofday(&now, NULL); + err = clock_gettime (clock_id, &now); assert (! err); if (now.tv_sec > abstime->tv_sec || (now.tv_sec == abstime->tv_sec - && now.tv_usec > ((abstime->tv_nsec + 999) / 1000))) + && now.tv_nsec > abstime->tv_nsec)) return ETIMEDOUT; timeout = (abstime->tv_sec - now.tv_sec) * 1000; - if (((abstime->tv_nsec + 999) / 1000) >= now.tv_usec) - timeout += (((abstime->tv_nsec + 999) / 1000) - now.tv_usec + 999) / 1000; + if (abstime->tv_nsec >= now.tv_nsec) + timeout += (abstime->tv_nsec - now.tv_nsec + 999999) / 1000000; else /* Need to do a carry. */ - timeout -= (now.tv_usec + 999) / 1000 - - ((abstime->tv_nsec + 999999) / 1000000); + timeout -= (now.tv_nsec - abstime->tv_nsec + 999999) / 1000000; err = __mach_msg (&msg, MACH_RCV_MSG | MACH_RCV_TIMEOUT, 0, sizeof msg, thread->wakeupmsg.msgh_remote_port, -- cgit v1.2.3