htl: Fix sem_wait race between read and gsync_wait
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Thu, 29 Dec 2022 23:40:18 +0000 (00:40 +0100)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Thu, 29 Dec 2022 23:41:24 +0000 (00:41 +0100)
If the value changes between sem_wait's read and the gsync_wait call,
the kernel will return KERN_INVALID_ARGUMENT, which we have to interpret
as the value having already changed.

This fixes applications (e.g. libgo) seeing sem_wait erroneously return
KERN_INVALID_ARGUMENT.

sysdeps/htl/sem-timedwait.c

index 1b1eec9..c610804 100644 (file)
@@ -79,7 +79,7 @@ __sem_timedwait_internal (sem_t *restrict sem,
                      ((unsigned int *) &sem->data) + SEM_VALUE_OFFSET,
                      0, flags);
 
-         if (err != 0)
+         if (err != 0 && err != KERN_INVALID_ARGUMENT)
            {
              /* Error, interruption or timeout, abort.  */
              if (err == KERN_TIMEDOUT)
@@ -138,7 +138,7 @@ __sem_timedwait_internal (sem_t *restrict sem,
                err = __lll_wait_intr (&isem->value,
                          SEM_NWAITERS_MASK, flags);
 
-             if (err != 0)
+             if (err != 0 && err != KERN_INVALID_ARGUMENT)
                {
                  /* Error, interruption or timeout, abort.  */
                  if (err == KERN_TIMEDOUT)