]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Guard mutex and condvar with gthreads macro [PR103638]
authorJonathan Wakely <jwakely@redhat.com>
Fri, 10 Dec 2021 11:44:29 +0000 (11:44 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 10 Dec 2021 14:05:46 +0000 (14:05 +0000)
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

index efbe3da8b6c70162e5da4709e9d7b7efe32a4bda..ba83398285c05eea4548a36ce2c83819ccf1674a 100644 (file)
@@ -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)
          {