feat: add SYS_FUTEX_WAIT and SYS_FUTEX_WAKE syscalls; revamp desktop application categories

This commit is contained in:
daniel committed 2026-10-13 07:11:39 +02:00
1 parent 60ca9c78c7
commit abfd9de8f6
35 files changed
+545 -70

No files matched your search

+22
View File
@@ -148,6 +148,28 @@ namespace montauk {
return (int)syscall0(montauk::abi::SYS_THREAD_SELF);
}
// Block while *addr == expected. Returns 0 when woken by futex_wake,
// WouldBlock if *addr had already changed, TimedOut when timeout_ns
// elapsed (FUTEX_WAIT_FOREVER = no deadline, 0 = check only, otherwise
// rounded up to the 1 ms tick). Futexes are private to the process.
// A 0 return is never spurious, but always re-check the condition.
inline int futex_wait(uint32_t* addr, uint32_t expected,
uint64_t timeout_ns = montauk::abi::FUTEX_WAIT_FOREVER) {
int64_t r = syscall3(montauk::abi::SYS_FUTEX_WAIT, (uint64_t)addr,
(uint64_t)expected, timeout_ns);
return r < 0 ? (int)-r : 0;
}
// Wake up to `count` waiters on addr, longest-waiting first. Returns the
// number woken, or a negative status for a bad address.
inline int futex_wake(uint32_t* addr, uint32_t count = 1) {
return (int)syscall2(montauk::abi::SYS_FUTEX_WAKE, (uint64_t)addr, (uint64_t)count);
}
inline int futex_wake_all(uint32_t* addr) {
return futex_wake(addr, montauk::abi::FUTEX_WAKE_ALL);
}
// Lightweight mutex backed by a single atomic word + the kernel
// yield syscall. Adequate for short critical sections; a heavier
// primitive can wrap mailbox_recv when blocking semantics are needed.