git-sem-intr
authorGNU Libc Maintainers <debian-glibc@lists.debian.org>
Tue, 5 May 2020 18:12:38 +0000 (19:12 +0100)
committerAurelien Jarno <aurel32@debian.org>
Tue, 5 May 2020 18:12:38 +0000 (19:12 +0100)
commit b2cdf72e5c496153050551f0ce704e9ef08ffeac
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Mon Feb 10 00:52:50 2020 +0000

    htl: Make sem_wait/sem_timedwait interruptible

Gbp-Pq: Topic hurd-i386
Gbp-Pq: Name git-sem-intr.diff

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 0b906eae5bc2fc129b39650ae3773358e01245b4..3951af8d486abf9bb07aa253725e12f6024aac0c 100644 (file)
@@ -109,6 +109,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 e7151e04f1241b99108e2a57fc382f195972e442..36ef27c276f846166be30323e86d6433d680d956 100644 (file)
@@ -273,6 +273,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 722e8240e3f857aadae6926e40b1b78773b8b975..062cec67c736c0c6e8792ddeb950a86b79d111fa 100644 (file)
@@ -29,6 +29,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)
@@ -53,12 +54,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)
@@ -81,7 +79,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 e476ddf30064b227e7894d7f7450fbf20e217e9a..f0b024fa46498e416e39fb2192e3c778bd378eb7 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 392e6596ea08fc5b4b420cae92273ac17bc6ba7e..6aecece79555d39eb98dd0a3e8d6fdaf598770da 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;