Skip to content

Commit 9f4022f

Browse files
committed
[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
1 parent ffcb4b4 commit 9f4022f

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

libcxx/include/thread

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,11 @@ sleep_for(const chrono::duration<_Rep, _Period>& __d)
362362
{
363363
if (__d > chrono::duration<_Rep, _Period>::zero())
364364
{
365-
#if defined(_LIBCPP_COMPILER_GCC) && (__powerpc__ || __POWERPC__)
366-
// GCC's long double const folding is incomplete for IBM128 long doubles.
367-
_LIBCPP_CONSTEXPR chrono::duration<long double> _Max = chrono::duration<long double>(ULLONG_MAX/1000000000ULL) ;
368-
#else
369-
_LIBCPP_CONSTEXPR chrono::duration<long double> _Max = chrono::nanoseconds::max();
370-
#endif
365+
// The standard guarantees a 64bit signed integer resolution for nanoseconds,
366+
// so use INT64_MAX / 1e9 as cut-off point. Use a constant to avoid <climits>
367+
// and issues with long double folding on PowerPC with GCC.
368+
_LIBCPP_CONSTEXPR chrono::duration<long double> _Max =
369+
chrono::duration<long double>(9223372036.0L);
371370
chrono::nanoseconds __ns;
372371
if (__d < _Max)
373372
{

0 commit comments

Comments
 (0)