]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
htl: Make sem_wait/sem_timedwait interruptible
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Mon, 10 Feb 2020 00:52:50 +0000 (00:52 +0000)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Mon, 10 Feb 2020 01:03:54 +0000 (01:03 +0000)
htl/Makefile
htl/pt-internal.h
sysdeps/htl/sem-timedwait.c
sysdeps/mach/htl/pt-block-intr.c [new file with mode: 0644]
sysdeps/mach/htl/pt-block.c
sysdeps/mach/htl/pt-timedblock-intr.c [new file with mode: 0644]
sysdeps/mach/htl/pt-timedblock.c

index 1b337489346c9dab828562d3a0ee5b4775876279..39294c64d12068a392a43a0466480de36e10c642 100644 (file)
@@ -108,6 +108,8 @@ libpthread-routines := pt-attr pt-attr-destroy pt-attr-getdetachstate           \
                                                                            \
        pt-block                                                            \
        pt-timedblock                                                       \
+       pt-block-intr                                                       \
+       pt-timedblock-intr                                                  \
        pt-wakeup                                                           \
        pt-docancel                                                         \
        pt-sysdep                                                           \
index 8ffe1bd9700273953853e7f76bb6295cc9427b0e..918c207c3ec589cc2badd0c014139f017f061790 100644 (file)
@@ -270,6 +270,14 @@ extern error_t __pthread_timedblock (struct __pthread *__restrict thread,
                                     const struct timespec *__restrict abstime,
                                     clockid_t clock_id);
 
+/* Block THREAD with interrupts.  */
+extern error_t __pthread_block_intr (struct __pthread *thread);
+
+/* Block THREAD until *ABSTIME is reached, with interrupts.  */
+extern error_t __pthread_timedblock_intr (struct __pthread *__restrict thread,
+                                         const struct timespec *__restrict abstime,
+                                         clockid_t clock_id);
+
 /* Wakeup THREAD.  */
 extern void __pthread_wakeup (struct __pthread *thread);
 
index 656da41184f193dff83bdf272b615705e18c0e83..a61acfd43f6af4f3824d80b378a369bb02b2cdf5 100644 (file)
@@ -30,6 +30,7 @@ __sem_timedwait_internal (sem_t *restrict sem,
   error_t err;
   int drain;
   struct __pthread *self;
+  clockid_t clock_id = CLOCK_REALTIME;
 
   __pthread_spin_lock (&sem->__lock);
   if (sem->__value > 0)
@@ -54,12 +55,9 @@ __sem_timedwait_internal (sem_t *restrict sem,
 
   /* Block the thread.  */
   if (timeout != NULL)
-    err = __pthread_timedblock (self, timeout, CLOCK_REALTIME);
+    err = __pthread_timedblock_intr (self, timeout, clock_id);
   else
-    {
-      err = 0;
-      __pthread_block (self);
-    }
+    err = __pthread_block_intr (self);
 
   __pthread_spin_lock (&sem->__lock);
   if (self->prevp == NULL)
@@ -82,7 +80,7 @@ __sem_timedwait_internal (sem_t *restrict sem,
 
   if (err)
     {
-      assert (err == ETIMEDOUT);
+      assert (err == ETIMEDOUT || err == EINTR);
       errno = err;
       return -1;
     }
diff --git a/sysdeps/mach/htl/pt-block-intr.c b/sysdeps/mach/htl/pt-block-intr.c
new file mode 100644 (file)
index 0000000..f15beb3
--- /dev/null
@@ -0,0 +1,6 @@
+#include <pt-internal.h>
+#define RETTYPE error_t
+#define RETURN(val) return val
+#define __pthread_block __pthread_block_intr
+#define MSG_OPTIONS MACH_RCV_INTERRUPT
+#include "pt-block.c"
index e1500dce339d0138d923578627dc52634be1f5ee..28bae157d183fd67d678ca1a59d49c39dcab06d2 100644 (file)
 
 #include <pt-internal.h>
 
+#ifndef MSG_OPTIONS
+# define MSG_OPTIONS 0
+#endif
+
+#ifndef RETTYPE
+# define RETTYPE void
+#endif
+
+#ifndef RETURN
+# define RETURN(val)
+#endif
+
 /* Block THREAD.  */
-void
+RETTYPE
 __pthread_block (struct __pthread *thread)
 {
   mach_msg_header_t msg;
   error_t err;
 
-  err = __mach_msg (&msg, MACH_RCV_MSG, 0, sizeof msg,
+  err = __mach_msg (&msg, MACH_RCV_MSG | MSG_OPTIONS, 0, sizeof msg,
                    thread->wakeupmsg.msgh_remote_port,
                    MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
+  if ((MSG_OPTIONS & MACH_RCV_INTERRUPT) && err == MACH_RCV_INTERRUPTED)
+    RETURN(EINTR);
   assert_perror (err);
+  RETURN(0);
 }
diff --git a/sysdeps/mach/htl/pt-timedblock-intr.c b/sysdeps/mach/htl/pt-timedblock-intr.c
new file mode 100644 (file)
index 0000000..70e1327
--- /dev/null
@@ -0,0 +1,3 @@
+#define __pthread_timedblock __pthread_timedblock_intr
+#define MSG_OPTIONS MACH_RCV_INTERRUPT
+#include "pt-timedblock.c"
index 63af869c90928e5a0e54ef60d064491ce6364b08..ead070e3972749d5925058be7d4402535076afe6 100644 (file)
 
 #include <pt-internal.h>
 
+#ifndef MSG_OPTIONS
+# define MSG_OPTIONS 0
+#endif
+
 /* Block THREAD.  */
 error_t
 __pthread_timedblock (struct __pthread *thread,
@@ -54,11 +58,13 @@ __pthread_timedblock (struct __pthread *thread,
     /* Need to do a carry.  */
     timeout -= (now.tv_nsec - abstime->tv_nsec + 999999) / 1000000;
 
-  err = __mach_msg (&msg, MACH_RCV_MSG | MACH_RCV_TIMEOUT, 0,
+  err = __mach_msg (&msg, MACH_RCV_MSG | MACH_RCV_TIMEOUT | MSG_OPTIONS, 0,
                    sizeof msg, thread->wakeupmsg.msgh_remote_port,
                    timeout, MACH_PORT_NULL);
   if (err == EMACH_RCV_TIMED_OUT)
     return ETIMEDOUT;
+  if ((MSG_OPTIONS & MACH_RCV_INTERRUPT) && err == MACH_RCV_INTERRUPTED)
+    return EINTR;
 
   assert_perror (err);
   return 0;