Mesa (staging/20.1): util: futex fixes for OpenBSD

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Sep 1 20:01:35 UTC 2020


Module: Mesa
Branch: staging/20.1
Commit: 8c39f6a64731a54a019d676e384f37f332c2fd68
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8c39f6a64731a54a019d676e384f37f332c2fd68

Author: Jonathan Gray <jsg at jsg.id.au>
Date:   Thu Feb 20 13:18:01 2020 +1100

util: futex fixes for OpenBSD

Fix absolute to relative timeout computation.

Add sanity checks to futex_wait()
- handle the NULL timeout pointer case
- avoid negative cases.

>From Matthieu Herrb and Scott Cheloha.

Fixes: c91997b6c43 ("util/futex: use futex syscall on OpenBSD")
Signed-off-by: Jonathan Gray <jsg at jsg.id.au>
Acked-by: Eric Engestrom <eric at engestrom.ch>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5630>
(cherry picked from commit c66c5b38e0ad136aa9301fd60aafea736d433c57)

---

 .pick_status.json |  2 +-
 src/util/futex.h  | 13 ++++++++++---
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 4104ca23ea2..c34de22206b 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -769,7 +769,7 @@
         "description": "util: futex fixes for OpenBSD",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "master_sha": null,
         "because_sha": "c91997b6c4395831a8de2b84e6ea2ff981a00e4b"
     },
diff --git a/src/util/futex.h b/src/util/futex.h
index 4d712e2ef2d..43097f4cd5b 100644
--- a/src/util/futex.h
+++ b/src/util/futex.h
@@ -100,9 +100,16 @@ static inline int futex_wake(uint32_t *addr, int count)
 
 static inline int futex_wait(uint32_t *addr, int32_t value, const struct timespec *timeout)
 {
-   struct timespec tsrel, tsnow;
-   clock_gettime(CLOCK_MONOTONIC, &tsnow); 
-   timespecsub(timeout, &tsrel, &tsrel);
+   struct timespec tsnow, tsrel;
+
+   if (timeout == NULL)
+      return futex(addr, FUTEX_WAIT, value, NULL, NULL);
+
+   clock_gettime(CLOCK_MONOTONIC, &tsnow);
+   if (timespeccmp(&tsnow, timeout, <))
+      timespecsub(timeout, &tsnow, &tsrel);
+   else
+      timespecclear(&tsrel);
    return futex(addr, FUTEX_WAIT, value, &tsrel, NULL);
 }
 



More information about the mesa-commit mailing list