about summary refs log tree commit diff
path: root/nptl/pthread_join_common.c
diff options
context:
space:
mode:
authorMike Crowe <mac@mcrowe.com>2019-10-31 10:03:21 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2019-11-01 11:23:43 -0300
commit69ca4b54c151cec42ccca5e05790efc1a8206b47 (patch)
treee239090413e1da5dbd3a9fc3ce54895da5624346 /nptl/pthread_join_common.c
parent893bbdd0072fbf96808e66af04b970e5b39171fb (diff)
downloadglibc-69ca4b54c151cec42ccca5e05790efc1a8206b47.tar.gz
glibc-69ca4b54c151cec42ccca5e05790efc1a8206b47.tar.xz
glibc-69ca4b54c151cec42ccca5e05790efc1a8206b47.zip
nptl: Add pthread_clockjoin_np
Introduce pthread_clockjoin_np as a version of pthread_timedjoin_np that
accepts a clockid_t parameter to indicate which clock the timeout should be
measured against. This mirrors the recently-added POSIX-proposed "clock"
wait functions.

Checked on x86_64-linux-gnu.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'nptl/pthread_join_common.c')
-rw-r--r--nptl/pthread_join_common.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/nptl/pthread_join_common.c b/nptl/pthread_join_common.c
index 4d91c6fbf2..998d227e2c 100644
--- a/nptl/pthread_join_common.c
+++ b/nptl/pthread_join_common.c
@@ -37,7 +37,7 @@ cleanup (void *arg)
    afterwards.  The kernel up to version 3.16.3 does not use the private futex
    operations for futex wake-up when the clone terminates.  */
 static int
-timedwait_tid (pid_t *tidp, const struct timespec *abstime)
+clockwait_tid (pid_t *tidp, clockid_t clockid, const struct timespec *abstime)
 {
   pid_t tid;
 
@@ -49,8 +49,10 @@ timedwait_tid (pid_t *tidp, const struct timespec *abstime)
     {
       struct timespec rt;
 
-      /* Get the current time.  */
-      __clock_gettime (CLOCK_REALTIME, &rt);
+      /* Get the current time. This can only fail if clockid is
+         invalid. */
+      if (__glibc_unlikely (__clock_gettime (clockid, &rt)))
+        return EINVAL;
 
       /* Compute relative timeout.  */
       rt.tv_sec = abstime->tv_sec - rt.tv_sec;
@@ -77,7 +79,8 @@ timedwait_tid (pid_t *tidp, const struct timespec *abstime)
 }
 
 int
-__pthread_timedjoin_ex (pthread_t threadid, void **thread_return,
+__pthread_clockjoin_ex (pthread_t threadid, void **thread_return,
+			clockid_t clockid,
 			const struct timespec *abstime, bool block)
 {
   struct pthread *pd = (struct pthread *) threadid;
@@ -122,7 +125,7 @@ __pthread_timedjoin_ex (pthread_t threadid, void **thread_return,
 
   /* BLOCK waits either indefinitely or based on an absolute time.  POSIX also
      states a cancellation point shall occur for pthread_join, and we use the
-     same rationale for posix_timedjoin_np.  Both timedwait_tid and the futex
+     same rationale for posix_timedjoin_np.  Both clockwait_tid and the futex
      call use the cancellable variant.  */
   if (block)
     {
@@ -132,7 +135,7 @@ __pthread_timedjoin_ex (pthread_t threadid, void **thread_return,
       pthread_cleanup_push (cleanup, &pd->joinid);
 
       if (abstime != NULL)
-	result = timedwait_tid (&pd->tid, abstime);
+	result = clockwait_tid (&pd->tid, clockid, abstime);
       else
 	{
 	  pid_t tid;
@@ -165,4 +168,3 @@ __pthread_timedjoin_ex (pthread_t threadid, void **thread_return,
 
   return result;
 }
-hidden_def (__pthread_timedjoin_ex)