public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Guard mutex and condvar with gthreads macro [PR103638]
@ 2021-12-10 14:08 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2021-12-10 14:08 UTC (permalink / raw)
  To: libstdc++, gcc-patches

Tested powerpc64le-linux --enable-threads={posix,single}, pushed to
trunk.  The testsuite is now clean for --enable-threads=single (apart
from the expected abi-check failures, because the baselines are for the
posix thread model).



A mutex and condition variable is used for timed waits on atomics if
there is no "platform wait" (e.g. futex) supported. But the use of those
types wasn't guarded by the _GLIBCXX_HAS_GTHREADS macro, causing errors
for --disable-threads builds. This fix allows <atomic> to work on
targets with futexes but no gthreads.

libstdc++-v3/ChangeLog:

	PR libstdc++/103638
	* include/bits/atomic_timed_wait.h: Check _GLIBCXX_HAS_GTHREADS
	before using std::mutex and std::__condvar.
---
 libstdc++-v3/include/bits/atomic_timed_wait.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libstdc++-v3/include/bits/atomic_timed_wait.h b/libstdc++-v3/include/bits/atomic_timed_wait.h
index efbe3da8b6c..ba83398285c 100644
--- a/libstdc++-v3/include/bits/atomic_timed_wait.h
+++ b/libstdc++-v3/include/bits/atomic_timed_wait.h
@@ -137,6 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 // (e.g. __ulock_wait())which is better than pthread_cond_clockwait
 #endif // ! PLATFORM_TIMED_WAIT
 
+#ifdef _GLIBCXX_HAS_GTHREADS
     // Returns true if wait ended before timeout.
     // _Clock must be either steady_clock or system_clock.
     template<typename _Clock, typename _Dur>
@@ -192,6 +193,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    return false;
 	  }
       }
+#endif // _GLIBCXX_HAS_GTHREADS
 
     struct __timed_waiter_pool : __waiter_pool_base
     {
@@ -239,6 +241,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	if (_M_deadline <= __now)
 	  return false;
 
+	// FIXME: this_thread::sleep_for not available #ifdef _GLIBCXX_NO_SLEEP
+
 	auto __elapsed = __now - _M_t0;
 	if (__elapsed > 128ms)
 	  {
-- 
2.31.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-10 14:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-10 14:08 [committed] libstdc++: Guard mutex and condvar with gthreads macro [PR103638] Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).