diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2021-06-13 21:11:55 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2021-06-13 21:11:55 +0000 |
commit | df5bd12faa10621734227be501b8fc3002fb12fe (patch) | |
tree | 1c999b42b35c9a3fe09750f384e781b3070d6270 /lib/librthread | |
parent | fcd1142203357ffd5d977e62dd403d94cddbe6e6 (diff) |
Save and restore errno around FUTEX_WAIT futex(2) operations. While there
remove the unused _wait() function in librthread such that we don't have to
add the save/restore sequence there.
Fixed building Python as a race with another thread unlocking a futex(2)
would make futex(2) set errno to EAGAIN which would confuse Python in
beleiving that readdir(2) failed instead of reaching the end of the
directory.
Spotted and tested by tb@
ok bluhm@
Diffstat (limited to 'lib/librthread')
-rw-r--r-- | lib/librthread/synch.h | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/librthread/synch.h b/lib/librthread/synch.h index e5c623e87a0..e6ad156778c 100644 --- a/lib/librthread/synch.h +++ b/lib/librthread/synch.h @@ -1,4 +1,4 @@ -/* $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 * @@ -25,23 +25,19 @@ _wake(volatile uint32_t *p, int n) 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; } @@ -57,8 +53,10 @@ _twait(volatile uint32_t *p, int val, clockid_t clockid, const struct timespec * return ETIMEDOUT; error = futex(p, FUTEX_WAIT, val, &rel, NULL); - if (error == -1) + if (error == -1) { error = errno; + errno = saved_errno; + } return error; } |