[libcxx-commits] [libcxx] 9f4022f - [libc++] Avoid <climits> dependency in <thread>

Joerg Sonnenberger via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 31 06:29:32 PDT 2021


Author: Joerg Sonnenberger
Date: 2021-03-31T15:28:16+02:00
New Revision: 9f4022ffeb20eff91c7461828592dc812ee5a28e

URL: https://github.com/llvm/llvm-project/commit/9f4022ffeb20eff91c7461828592dc812ee5a28e
DIFF: https://github.com/llvm/llvm-project/commit/9f4022ffeb20eff91c7461828592dc812ee5a28e.diff

LOG: [libc++] Avoid <climits> dependency in <thread>

The standard guarantees sleep durations of 2^63-1 nanoseconds to work.
Instead of depending on INT64_MAX or ULONGLONG_MAX to exist via the
header pollution, fold the constant directly. That has the additional
positive side effect that it avoids long double arithmetic bugs in GCC.

Differential Revision: https://reviews.llvm.org/D99516

Added: 
    

Modified: 
    libcxx/include/thread

Removed: 
    


################################################################################
diff  --git a/libcxx/include/thread b/libcxx/include/thread
index 34e0c2a239163..ff3c7463c094d 100644
--- a/libcxx/include/thread
+++ b/libcxx/include/thread
@@ -362,12 +362,11 @@ sleep_for(const chrono::duration<_Rep, _Period>& __d)
 {
     if (__d > chrono::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 chrono::duration<long double> _Max = chrono::duration<long double>(ULLONG_MAX/1000000000ULL) ;
-#else
-        _LIBCPP_CONSTEXPR chrono::duration<long double> _Max = chrono::nanoseconds::max();
-#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 chrono::duration<long double> _Max =
+            chrono::duration<long double>(9223372036.0L);
         chrono::nanoseconds __ns;
         if (__d < _Max)
         {


        


More information about the libcxx-commits mailing list