mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
rework openbsd futexes a little
This commit is contained in:
+13
-6
@@ -512,22 +512,29 @@ typedef std::atomic<int32_t> Futex;
|
|||||||
typedef volatile int32_t Footex;
|
typedef volatile int32_t Footex;
|
||||||
|
|
||||||
gb_internal void tpool_wake_addr(Futex *addr) {
|
gb_internal void tpool_wake_addr(Futex *addr) {
|
||||||
int ret = futex((volatile uint32_t *)addr, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1, NULL, NULL);
|
for (;;) {
|
||||||
if (ret == -1) {
|
int ret = futex((volatile uint32_t *)addr, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1, NULL, NULL);
|
||||||
perror("Futex wake");
|
if (ret == -1) {
|
||||||
GB_PANIC("futex wake fail");
|
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) {
|
gb_internal void tpool_wait_on_addr(Futex *addr, Footex val) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int ret = futex((volatile uint32_t *)addr, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, val, NULL, NULL);
|
int ret = futex((volatile uint32_t *)addr, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, val, NULL, NULL);
|
||||||
if (ret != -1) {
|
if (ret == -1) {
|
||||||
if (*addr != val) {
|
if (*addr != val) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
if (errno == ETIMEDOUT || errno == EINTR) {
|
if (errno == ETIMEDOUT || errno == EINTR) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user