[PATCH] D80679: Avoid hidden <climits> dependency in <thread>

Joerg Sonnenberger via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 27 17:29:16 PDT 2020


joerg created this revision.
joerg added a reviewer: mclow.lists.
Herald added a subscriber: steven.zhang.

sleep_for tries to convert arbitrary durations toward nanosecond resolution in a way that avoids truncation. The nanosecond timer is declared using long long, but the minimum required size of 64bit signed is enough for all computation needs. Avoid doing a long double constexpr computation here as older GCC versions on PowerPC have problems folding the double-double type and also avoid the additional header include at the same time. The constant equals about 290 years and should be good enough.


https://reviews.llvm.org/D80679

Files:
  libcxx/include/thread


Index: libcxx/include/thread
===================================================================
--- libcxx/include/thread
+++ libcxx/include/thread
@@ -367,12 +367,10 @@
     using namespace chrono;
     if (__d > duration<_Rep, _Period>::zero())
     {
-#if defined(_LIBCPP_COMPILER_GCC) && (__powerpc__ || __POWERPC__)
-    //  GCC's long double const folding is incomplete for IBM128 long doubles.
-        _LIBCPP_CONSTEXPR duration<long double> _Max = nanoseconds::max();
-#else
-        _LIBCPP_CONSTEXPR duration<long double> _Max = duration<long double>(ULLONG_MAX/1000000000ULL) ;
-#endif
+        // The standard guarantees a 64bit signed integer resolution for nanoseconds,
+        // so use INT64_MAX / 1e9 as cut-off point. Use a constant to avoid <climits>
+        // and issues with long double folding on PowerPC with GCC.
+        _LIBCPP_CONSTEXPR duration<long double> _Max = duration<long double>(9223372036.0L) ;
         nanoseconds __ns;
         if (__d < _Max)
         {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80679.266706.patch
Type: text/x-patch
Size: 1000 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200528/64744f6d/attachment.bin>


More information about the llvm-commits mailing list