[gcc r16-991] libstdc++: Simplify futex wrapper functions for atomic wait/notify
Jonathan Wakely
redi@gcc.gnu.org
Fri May 30 09:08:18 GMT 2025
https://gcc.gnu.org/g:f52948bf8e5f3b0a72a903b3b26e5d54d2929723
commit r16-991-gf52948bf8e5f3b0a72a903b3b26e5d54d2929723
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Jan 9 23:03:50 2025 +0000
libstdc++: Simplify futex wrapper functions for atomic wait/notify
libstdc++-v3/ChangeLog:
* include/bits/atomic_wait.h (__platform_wait): Change function
template to a normal function. The parameter is always
__platform_wait_t* which is just int* for this implementation of
the function.
(__platform_notify): Likewise.
Diff:
---
libstdc++-v3/include/bits/atomic_wait.h | 40 ++++++++++++++++-----------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h
index 725ea030245d..5fd00c22565b 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -108,27 +108,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__bitset_match_any = -1
};
- template<typename _Tp>
- void
- __platform_wait(const _Tp* __addr, __platform_wait_t __val) noexcept
- {
- auto __e = syscall (SYS_futex, static_cast<const void*>(__addr),
- static_cast<int>(__futex_wait_flags::__wait_private),
- __val, nullptr);
- if (!__e || errno == EAGAIN)
- return;
- if (errno != EINTR)
- __throw_system_error(errno);
- }
+ // If the futex *__addr is equal to __val, wait on the futex until woken.
+ inline void
+ __platform_wait(const int* __addr, int __val) noexcept
+ {
+ auto __e = syscall (SYS_futex, __addr,
+ static_cast<int>(__futex_wait_flags::__wait_private),
+ __val, nullptr);
+ if (!__e || errno == EAGAIN)
+ return;
+ if (errno != EINTR)
+ __throw_system_error(errno);
+ }
- template<typename _Tp>
- void
- __platform_notify(const _Tp* __addr, bool __all) noexcept
- {
- syscall (SYS_futex, static_cast<const void*>(__addr),
- static_cast<int>(__futex_wait_flags::__wake_private),
- __all ? INT_MAX : 1);
- }
+ // Wake threads waiting on the futex *__addr.
+ inline void
+ __platform_notify(const int* __addr, bool __all) noexcept
+ {
+ syscall (SYS_futex, __addr,
+ static_cast<int>(__futex_wait_flags::__wake_private),
+ __all ? INT_MAX : 1);
+ }
#endif
inline void
More information about the Libstdc++-cvs
mailing list