From e6b5a04981010be80a3249c76e7f8d5a3d88a0d5 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sun, 22 Apr 2012 00:38:26 +0200 Subject: [PATCH 2/3] __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(-) 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, -- 1.7.9.5