MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / spinForWork

Method spinForWork

modules/core/task/src/task2.cpp:236–267  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234 }
235
236 void spinForWork()
237 {
238 SkrZoneScopedN("Worker::SpinForWork");
239 constexpr auto duration = std::chrono::milliseconds(1);
240 auto start = std::chrono::high_resolution_clock::now();
241 int lastStolen = id;
242 while (std::chrono::high_resolution_clock::now() - start < duration)
243 {
244 if (work.num > 0) {
245 return;
246 }
247 if(lastStolen == id)
248 {
249 //spin
250 for (int i = 0; i < 256; i++) // Empirically picked magic number!
251 {
252 // atomic_queue::spin_loop_pause();
253 // clang-format off
254 nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
255 nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
256 nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
257 nop(); nop(); nop(); nop(); nop(); nop(); nop(); nop();
258 // clang-format on
259 if (work.num > 0) {
260 return;
261 }
262 }
263 }
264 lastStolen = stealWork(lastStolen);
265 std::this_thread::yield();
266 }
267 }
268
269 void waitForWork()
270 {

Callers

nothing calls this directly

Calls 1

nopFunction · 0.85

Tested by

no test coverage detected