diff options
| author | Colin Davidson <colrdavidson@gmail.com> | 2022-12-29 12:00:16 -0800 |
|---|---|---|
| committer | Colin Davidson <colrdavidson@gmail.com> | 2022-12-29 12:00:16 -0800 |
| commit | 27ba1d596c5b68f856b4e74c72bf28439daf4807 (patch) | |
| tree | c94706a91427445a3e1809f91ce57f2d34e37168 /src/threading.cpp | |
| parent | 98e5523f2f6d36960d32041a2d5a1de96ef6e5a5 (diff) | |
rework openbsd futexes a little
Diffstat (limited to 'src/threading.cpp')
| -rw-r--r-- | src/threading.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/threading.cpp b/src/threading.cpp index c065663b2..493e57c91 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -512,22 +512,29 @@ typedef std::atomic<int32_t> Futex; typedef volatile int32_t Footex; gb_internal void tpool_wake_addr(Futex *addr) { - int ret = futex((volatile uint32_t *)addr, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1, NULL, NULL); - if (ret == -1) { - perror("Futex wake"); - GB_PANIC("futex wake fail"); + for (;;) { + int ret = futex((volatile uint32_t *)addr, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1, NULL, NULL); + if (ret == -1) { + if (errno == ETIMEDOUT || errno == EINTR) { + continue; + } + + perror("Futex wake"); + GB_PANIC("futex wake fail"); + } else if (ret == 1) { + return; + } } } gb_internal void tpool_wait_on_addr(Futex *addr, Footex val) { for (;;) { int ret = futex((volatile uint32_t *)addr, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, val, NULL, NULL); - if (ret != -1) { + if (ret == -1) { if (*addr != val) { return; } - } else { if (errno == ETIMEDOUT || errno == EINTR) { continue; } |