-/* $OpenBSD: synch.h,v 1.6 2021/05/21 16:52:42 kettenis Exp $ */
+/* $OpenBSD: synch.h,v 1.7 2021/06/13 21:11:54 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 saved_errno = errno;
int error;
if (abs == NULL) {
error = futex(p, FUTEX_WAIT_PRIVATE, val, NULL, NULL);
- if (error == -1)
+ if (error == -1) {
error = errno;
+ errno = saved_errno;
+ }
return error;
}
return ETIMEDOUT;
error = futex(p, FUTEX_WAIT_PRIVATE, val, &rel, NULL);
- if (error == -1)
+ if (error == -1) {
error = errno;
+ errno = saved_errno;
+ }
return error;
}
-/* $OpenBSD: synch.h,v 1.7 2021/05/21 16:52:42 kettenis Exp $ */
+/* $OpenBSD: synch.h,v 1.8 2021/06/13 21:11:54 kettenis Exp $ */
/*
* Copyright (c) 2017 Martin Pieuchot
*
return futex(p, FUTEX_WAKE, n, NULL, NULL);
}
-static inline void
-_wait(volatile uint32_t *p, int val)
-{
- while (*p != (uint32_t)val)
- futex(p, FUTEX_WAIT, val, NULL, NULL);
-}
-
static inline int
_twait(volatile uint32_t *p, int val, clockid_t clockid, const struct timespec *abs)
{
struct timespec rel;
+ int saved_errno = errno;
int error;
if (abs == NULL) {
error = futex(p, FUTEX_WAIT, val, NULL, NULL);
- if (error == -1)
+ if (error == -1) {
error = errno;
+ errno = saved_errno;
+ }
return error;
}
return ETIMEDOUT;
error = futex(p, FUTEX_WAIT, val, &rel, NULL);
- if (error == -1)
+ if (error == -1) {
error = errno;
+ errno = saved_errno;
+ }
return error;
}