-/* $OpenBSD: synch.h,v 1.5 2020/07/06 13:33:06 pirofti Exp $ */
+/* $OpenBSD: synch.h,v 1.6 2021/05/21 16:52:42 kettenis Exp $ */
/*
* Copyright (c) 2017 Martin Pieuchot
*
_twait(volatile uint32_t *p, int val, clockid_t clockid, const struct timespec *abs)
{
struct timespec rel;
+ int error;
- if (abs == NULL)
- return futex(p, FUTEX_WAIT_PRIVATE, val, NULL, NULL);
+ if (abs == NULL) {
+ error = futex(p, FUTEX_WAIT_PRIVATE, val, NULL, NULL);
+ if (error == -1)
+ error = errno;
+ return error;
+ }
if (abs->tv_nsec >= 1000000000 || WRAP(clock_gettime)(clockid, &rel))
- return (EINVAL);
+ return EINVAL;
rel.tv_sec = abs->tv_sec - rel.tv_sec;
if ((rel.tv_nsec = abs->tv_nsec - rel.tv_nsec) < 0) {
rel.tv_nsec += 1000000000;
}
if (rel.tv_sec < 0)
- return (ETIMEDOUT);
+ return ETIMEDOUT;
- return futex(p, FUTEX_WAIT_PRIVATE, val, &rel, NULL);
+ error = futex(p, FUTEX_WAIT_PRIVATE, val, &rel, NULL);
+ if (error == -1)
+ error = errno;
+ return error;
}
static inline int
-/* $OpenBSD: synch.h,v 1.6 2019/10/24 12:32:18 sthen Exp $ */
+/* $OpenBSD: synch.h,v 1.7 2021/05/21 16:52:42 kettenis Exp $ */
/*
* Copyright (c) 2017 Martin Pieuchot
*
_twait(volatile uint32_t *p, int val, clockid_t clockid, const struct timespec *abs)
{
struct timespec rel;
+ int error;
- if (abs == NULL)
- return futex(p, FUTEX_WAIT, val, NULL, NULL);
+ if (abs == NULL) {
+ error = futex(p, FUTEX_WAIT, val, NULL, NULL);
+ if (error == -1)
+ error = errno;
+ return error;
+ }
if (abs->tv_nsec >= 1000000000 || clock_gettime(clockid, &rel))
- return (EINVAL);
+ return EINVAL;
rel.tv_sec = abs->tv_sec - rel.tv_sec;
if ((rel.tv_nsec = abs->tv_nsec - rel.tv_nsec) < 0) {
rel.tv_nsec += 1000000000;
}
if (rel.tv_sec < 0)
- return (ETIMEDOUT);
+ return ETIMEDOUT;
- return futex(p, FUTEX_WAIT, val, &rel, NULL);
+ error = futex(p, FUTEX_WAIT, val, &rel, NULL);
+ if (error == -1)
+ error = errno;
+ return error;
}
static inline int