commit | b858a858c3c2d85529deacea847fe016ecf93673 | [log] [tgz] |
---|---|---|
author | Schrodinger ZHU Yifan <yifanzhu@rochester.edu> | Tue May 07 10:47:41 2024 -0400 |
committer | Copybara-Service <copybara-worker@google.com> | Tue May 07 07:54:32 2024 -0700 |
tree | 95cf4e500e341131caa4d6099b14fdc2ef030f46 | |
parent | 49c2af031e72d9f5510003210842f51c56cf447a [diff] |
[libc] clean up futex usage (#91163) # Motivation Futex syscalls are widely used in our codebase as synchronization mechanism. Hence, it may be worthy to abstract out the most common routines (wait and wake). On the other hand, C++20 also provides `std::atomic_notify_one/std::atomic_wait/std::atomic_notify_all` which align with such functionalities. This PR introduces `Futex` as a subtype of `cpp::Atomic<FutexWordType>` with additional `notify_one/notify_all/wait` operations. Providing such wrappers also make future porting easier. For example, FreeBSD's `_umtx_op` and Darwin's `ulock` can be wrapped in a similar manner. ### Similar Examples 1. [bionic futex](https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/bionic/bionic_futex.cpp) 2. [futex in Rust's std](https://github.com/rust-lang/rust/blob/8cef37dbb67e9c80702925f19cf298c4203991e4/library/std/src/sys/pal/unix/futex.rs#L21) GitOrigin-RevId: ab3a9e724d87a4272782f76b90fb0872a6a86939