Add sanity checks to futex_wait()
- handle the NULL timeout pointer case - avoid negative cases. Suggested by cheloha@ ok cheloha@, jsg@
This commit is contained in:
parent
863ee81424
commit
8e89b73ce9
@ -97,9 +97,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;
|
||||
struct timespec tsnow, tsrel;
|
||||
|
||||
if (timeout == NULL)
|
||||
return futex(addr, FUTEX_WAIT, value, NULL, NULL);
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &tsnow);
|
||||
timespecsub(timeout, &tsnow, &tsrel);
|
||||
if (timespeccmp(&tsnow, timeout, <))
|
||||
timespecsub(timeout, &tsnow, &tsrel);
|
||||
else
|
||||
timespecclear(&tsrel);
|
||||
return futex(addr, FUTEX_WAIT, value, &tsrel, NULL);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user