diff mbox series

[3/4] Adjust wait logic to limit spurious eval of wait predicate.

Message ID 20200606212621.1611106-1-rodgert@appliantology.com
State New
Headers show
Series None | expand

Commit Message

Thomas Rodgers June 6, 2020, 9:26 p.m. UTC
* include/bits/atomic_wait.h (__waiters::_M_do_wait): adjust wakeup
          logic.
---
 libstdc++-v3/include/bits/atomic_wait.h | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h
index 92c1e2526ed..cce11ae1cf5 100644
--- a/libstdc++-v3/include/bits/atomic_wait.h
+++ b/libstdc++-v3/include/bits/atomic_wait.h
@@ -138,24 +138,22 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       }
 
       void
-      _M_do_wait(__platform_wait_t __version) noexcept
+      _M_do_wait(__platform_wait_t __old) noexcept
       {
+	__platform_wait_t __cur;
+	__atomic_load(&_M_ver, &__cur, __ATOMIC_ACQUIRE);
+	while (__cur == __old)
+	  {
 #ifdef _GLIBCXX_HAVE_LINUX_FUTEX
-	__platform_wait(&_M_ver, __version);
+	    __platform_wait(&_M_ver, __cur);
 #else
-	__platform_wait_t __cur = 0;
-	while (__cur <= __version)
-	  {
 	    __waiters::__lock_t __l(_M_mtx);
 	    auto __e = __gthread_cond_wait(&_M_cv, __l.mutex()->native_handle());
 	    if (__e)
 	      std::terminate();
-	    __platform_wait_t __last = __cur;
+#endif
 	    __atomic_load(&_M_ver, &__cur, __ATOMIC_ACQUIRE);
-	    if (__cur < __last)
-	      break; // break the loop if version overflows
 	  }
-#endif
       }
 
       __platform_wait_t