MCPcopy Create free account
hub / github.com/FastLED/FastLED / native_sleep

Function native_sleep

src/platforms/stub/thread_stub_stl.h:66–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64/// @tparam Period A fl::ratio representing the tick period
65template<typename Rep, typename Period>
66inline void native_sleep(const fl::chrono::duration<Rep, Period>& sleep_duration) FL_NOEXCEPT {
67 // Convert to nanoseconds
68 auto ns = fl::chrono::duration_cast<fl::chrono::nanoseconds>(sleep_duration).count();
69
70 if (ns <= 0) {
71 return;
72 }
73
74#ifdef FL_IS_WIN
75 // Windows: Sleep takes milliseconds
76 // Convert nanoseconds to milliseconds (round up)
77 unsigned long ms = static_cast<unsigned long>((ns + 999999) / 1000000);
78 Sleep(ms) FL_NOEXCEPT;
79#else
80 // POSIX: Use nanosleep
81 struct timespec ts;
82 ts.tv_sec = ns / 1000000000LL;
83 ts.tv_nsec = ns % 1000000000LL;
84
85 // Handle EINTR (interrupted by signal) by retrying
86 while (::nanosleep(&ts, &ts) == -1 && errno == EINTR) {
87 // Continue with remaining time in ts
88 }
89#endif
90}
91
92} // namespace detail
93

Callers 1

sleep_forFunction · 0.85

Calls 1

countMethod · 0.45

Tested by

no test coverage detected