From: Jonathan Wakely Date: Thu, 9 Jan 2025 23:03:50 +0000 (+0000) Subject: libstdc++: Simplify futex wrapper functions for atomic wait/notify X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f52948bf8e5f3b0a72a903b3b26e5d54d2929723;p=thirdparty%2Fgcc.git 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 --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h index 725ea030245..5fd00c22565 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 - void - __platform_wait(const _Tp* __addr, __platform_wait_t __val) noexcept - { - auto __e = syscall (SYS_futex, static_cast(__addr), - static_cast(__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(__futex_wait_flags::__wait_private), + __val, nullptr); + if (!__e || errno == EAGAIN) + return; + if (errno != EINTR) + __throw_system_error(errno); + } - template - void - __platform_notify(const _Tp* __addr, bool __all) noexcept - { - syscall (SYS_futex, static_cast(__addr), - static_cast(__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(__futex_wait_flags::__wake_private), + __all ? INT_MAX : 1); + } #endif inline void