MCPcopy Create free account
hub / github.com/cameron314/concurrentqueue / thread_sleep_v3

Function thread_sleep_v3

benchmarks/tbb/tbb_thread.cpp:167–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167void thread_sleep_v3(const tick_count::interval_t &i)
168{
169#if _WIN32||_WIN64
170 tick_count t0 = tick_count::now();
171 tick_count t1 = t0;
172 for(;;) {
173 double remainder = (i-(t1-t0)).seconds()*1e3; // milliseconds remaining to sleep
174 if( remainder<=0 ) break;
175 DWORD t = remainder>=INFINITE ? INFINITE-1 : DWORD(remainder);
176#if !__TBB_WIN8UI_SUPPORT
177 Sleep( t );
178#else
179 std::chrono::milliseconds sleep_time( t );
180 std::this_thread::sleep_for( sleep_time );
181#endif
182 t1 = tick_count::now();
183 }
184#else
185 struct timespec req;
186 double sec = i.seconds();
187
188 req.tv_sec = static_cast<long>(sec);
189 req.tv_nsec = static_cast<long>( (sec - req.tv_sec)*1e9 );
190 nanosleep(&req, NULL);
191#endif // _WIN32||_WIN64
192}
193
194} // internal
195} // tbb

Callers 1

sleepFunction · 0.85

Calls 1

secondsMethod · 0.80

Tested by

no test coverage detected