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: c91997b6c4
("util/futex: use futex syscall on OpenBSD")
Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
Acked-by: Eric Engestrom <eric@engestrom.ch>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5630>
This commit is contained in:
parent
0398caa97f
commit
c66c5b38e0
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue