| 165 | } |
| 166 | |
| 167 | void 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 |