30 #ifndef _GLIBCXX_THIS_THREAD_SLEEP_H
31 #define _GLIBCXX_THIS_THREAD_SLEEP_H 1
33 #pragma GCC system_header
35 #if __cplusplus >= 201103L
38 #ifdef _GLIBCXX_USE_NANOSLEEP
43 namespace std _GLIBCXX_VISIBILITY(default)
45 _GLIBCXX_BEGIN_NAMESPACE_VERSION
58 #ifndef _GLIBCXX_NO_SLEEP
60 #ifndef _GLIBCXX_USE_NANOSLEEP
66 template<
typename _Rep,
typename _Period>
70 if (__rtime <= __rtime.zero())
72 auto __s = chrono::duration_cast<chrono::seconds>(__rtime);
73 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__rtime - __s);
74 #ifdef _GLIBCXX_USE_NANOSLEEP
75 struct ::timespec __ts =
77 static_cast<std::time_t
>(__s.count()),
78 static_cast<long>(__ns.count())
80 while (::nanosleep(&__ts, &__ts) == -1 && errno == EINTR)
83 __sleep_for(__s, __ns);
88 template<
typename _Clock,
typename _Duration>
92 #if __cplusplus > 201703L
93 static_assert(chrono::is_clock_v<_Clock>);
95 auto __now = _Clock::now();
96 if (_Clock::is_steady)
102 while (__now < __atime)
105 __now = _Clock::now();
113 _GLIBCXX_END_NAMESPACE_VERSION
duration< int64_t > seconds
seconds
duration< int64_t, nano > nanoseconds
nanoseconds
ISO C++ entities toplevel namespace is std.
void sleep_until(const chrono::time_point< _Clock, _Duration > &__atime)
this_thread::sleep_until
void sleep_for(const chrono::duration< _Rep, _Period > &__rtime)
this_thread::sleep_for
chrono::duration represents a distance between two points in time
chrono::time_point represents a point in time as measured by a clock